2015-09-13 87 views
1

我使用实体框架与2个contructors统一的构造函数:为实体框架

public ControlConfigContext() 
    : base("Name=ControlConfigContext") 
{ 
    this.Configuration.ProxyCreationEnabled = false; 
    this.Configuration.LazyLoadingEnabled = false; 
    this.Configuration.AutoDetectChangesEnabled = true; 
    this.Database.Log = s => Debug.WriteLine(s); 
} 

public ControlConfigContext(DbConnection connection) 
    : base(connection, true) 
{ 
    // Required by Effort 
} 

public interface IDbContext 
{ 
    int SaveChanges(); 

    void Dispose(); 

    void BeginTransaction(); 

    void Rollback(); 

    void Commit(); 
} 

在统一登记方使用:

container.RegisterType<IDbContext, ControlConfigContext>(new PerResolveLifetimeManager()); 

我怎么能告诉统一选择的第一个构造函数(没有DbConnection作为参数)?另外我不想在构造函数上使用注释来修改RegisterType的行。

回答

1

我就这样解决了!我希望它能帮助别人。

container.RegisterType<IDbContext, ControlConfigContext>(new PerResolveLifetimeManager(), new InjectionConstructor());