Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create InstanceProducer<TService> #39

Closed
dotnetjunkie opened this issue May 8, 2015 · 0 comments
Closed

Create InstanceProducer<TService> #39

dotnetjunkie opened this issue May 8, 2015 · 0 comments
Assignees
Milestone

Comments

@dotnetjunkie
Copy link
Collaborator

Currently the InstanceProducer class is non-generic. This means that it's GetInstance method returns object. This causes users to have to apply casting themselves if they use the InstanceProducer class as follows:

var prod = Lifestyle.Scoped.CreateProducer<DbContext>(() => new DbContext("constr"), container);

container.RegisterSingle<IUnitOfWork>(
    new DbContextUnitOfWork(() => (DbContext)prod.GetInstance()));

If the Lifestyle.CreateProducer<T> methods would return an InstanceProducer<T> instead, this would make scenarios like these much cleaner, because that would allow the user to minimize the code to the following:

var prod = Lifestyle.Scoped.CreateProducer<DbContext>(() => new DbContext("constr"), container);

container.RegisterSingle<IUnitOfWork>(new DbContextUnitOfWork(prod.GetInstance));
@dotnetjunkie dotnetjunkie added this to the Simple Injector v3.0 milestone May 8, 2015
@dotnetjunkie dotnetjunkie self-assigned this May 22, 2015
dotnetjunkie pushed a commit that referenced this issue May 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant