show使用StructureMap时预期的方法名称

时间:2017-07-28 15:56:02

标签: c# structuremap structuremap4

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

for scan in outer: scan = [str(x) for x in scan if x] for value in scan: print value print type(value) sql_insert = ('INSERT INTO langmuir_data(currentI)' 'VALUES("%s")') cursor.execute(sql_insert, str(value)) 中的IUnitOfWork界面和DALIUnitOfWork的{​​Def}功能。

ApplicationDbContext:

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

它告诉我这个错误:

  

严重级代码描述项目文件行抑制状态   错误CS0149方法名称预期BimehKosarFinal E:\ myproject \ BimehKosarFinal \ BimehKosarFinal \ StructureMap \ StructureMapDefnation.cs 28活动

在此行中:

 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;
    }
}

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

1 个答案:

答案 0 :(得分:1)

删除最后一个(),然后写

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

或者

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