کیانوش
کیانوش

Reputation: 3

show Method name expected when using StructureMap

i using StructureMap in my project for using DepencyInjection . I have 5 project in my solution.

I have IUnitOfWork interface in DAL and I Defnation Function of IUnitOfWork in 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>();
    }

.
.
.

now when I want to register IUnitOfWork in main project :

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

it show me this error :

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

in this line :

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

whats the problem ? how can I solve this problem ?

Upvotes: 0

Views: 75

Answers (1)

VahidN
VahidN

Reputation: 19166

remove the last (), and write

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

Or

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

Upvotes: 1

Related Questions