Skip to content

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.

2 participants