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

Add RegisterTo<TService, TTarget> method #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hendryten
Copy link

Short hand for:

Register<TService, TTarget>(factory => factory.GetInstance<TTarget>())

This is useful for registering a group of interfaces that actually resolve to the same instance registered with a specific lifetime.

The following:

var container = new ServiceContainer();
container.Register<Concrete>(new PerRequestLifeTime());
container.Register<IInterfaceOne, Concrete>(factory => factory.GetInstance<Concrete>());
container.Register<IInterfaceTwo, Concrete>(factory => factory.GetInstance<Concrete>());

can now be written in:

var container = new ServiceContainer();
container.Register<Concrete>(new PerRequestLifeTime());
container.RegisterTo<IInterfaceOne, Concrete>();
container.RegisterTo<IInterfaceTwo, Concrete>();

Short hand for: Register<TService, TTarget>(factory =>
factory.GetInstance<TTarget>())
@minskowl
Copy link

Better in one call
var container = new ServiceContainer();
container.Register<IInterfaceOne,IInterfaceTwo, Concrete>(new PerRequestLifeTime());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants