Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registering types with lambda expression

I was wondering how do I achieve such a feature in the UnityContainer:

container.RegisterType<IDummy>(Func<IDummy>) // deferred resolution
like image 795
Gena Verdel Avatar asked Jun 17 '14 06:06

Gena Verdel


1 Answers

If you're going to register factory instead of instance, try this:

container.RegisterType<IDummy>(new InjectionFactory(context => new Dummy()));

Just replace "context => new Dummy()" with your lambda.

like image 105
Stan Avatar answered Nov 09 '22 01:11

Stan