Reputation: 975
I am using entity framework with those 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();
}
On the unity registration side I use:
container.RegisterType<IDbContext, ControlConfigContext>(new PerResolveLifetimeManager());
How can I tell unity to select the first constructor (without DbConnection as parameter) ? Also I don't want to use annotations on the constructor just to modify the line with RegisterType.
Upvotes: 1
Views: 82
Reputation: 975
I solved like this! I hope it helps somebody.
container.RegisterType<IDbContext, ControlConfigContext>(new PerResolveLifetimeManager(), new InjectionConstructor());
Upvotes: 1