显示使用 StructureMap 时预期的方法名称

show Method name expected when using StructureMap

我在我的项目中使用 StructureMap 来使用 DepencyInjection 。我的解决方案中有 5 个项目。

我在DAL中有IUnitOfWork接口,在ApplicationDbContext中有IUnitOfWork的定义函数。

ApplicationDbContext :

public class ApplicationDbContext : DbContext, IUnitOfWork
{
    public ApplicationDbContext()
        : base("ApplicationDBContext")
    {
    }

    public virtual DbSet<User> Users { get; set; }
    public void ForceDatabaseInitialize()
    {
        Database.Initialize(true);
    }

    public static ApplicationDbContext Create()
    {
        return new ApplicationDbContext();
    }
    #region IUnitOfWork Members

    public void MarkAsDeleted<TEntity>(TEntity entity) where TEntity : class
    {
        Entry(entity).State = EntityState.Deleted;
    }
    public new IDbSet<TEntity> Set<TEntity>() where TEntity : class
    {
        return base.Set<TEntity>();
    }

.
.
.

现在我想在主项目中注册 IUnitOfWork :

 public static class StructureMapDefnation
{
    private static readonly Lazy<Container> _containerBuilder =
        new Lazy<Container>(defaultContainer, LazyThreadSafetyMode.ExecutionAndPublication);
    public static IContainer Container
    {
        get { return _containerBuilder.Value; }
    }
    private static Container defaultContainer()
    {
        var container = new Container(ioc =>
        {
            // map same interface to different concrete classes
            ioc.For<IUser>().Use<EfUserService>();
            ioc.For<IUnitOfWork>().Use(() => new ApplicationDbContext())();
        });
        container.AssertConfigurationIsValid();

        return container;
    }
}

它告诉我这个错误:

Severity Code Description Project File Line Suppression State Error CS0149 Method name expected BimehKosarFinal E:\myproject\BimehKosarFinal\BimehKosarFinal\StructureMap\StructureMapDefnation.cs 28 Active

这一行:

ioc.For<IUnitOfWork>().Use(() => new ApplicationDbContext())();

有什么问题吗?我该如何解决这个问题?

去掉最后一个(),写

ioc.For<IUnitOfWork>().Use(() => new ApplicationDbContext());

或者

ioc.For<IUnitOfWork>().Use<ApplicationDbContext>();