1

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.

1 Answer 1

1

I solved like this! I hope it helps somebody.

container.RegisterType<IDbContext, ControlConfigContext>(new PerResolveLifetimeManager(), new InjectionConstructor());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.