Timeline for Using Autofac to do DI in a static factory method
Current License: CC BY-SA 3.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 5, 2017 at 10:04 | comment | added | t3chb0t |
It turns out that without .As<T> this won't work scope.Resolve<IEnumerable<ICommand>>(); when T is an ICommand registered only with .RegisterType<Copy>() .
|
|
Nov 4, 2017 at 18:39 | comment | added | user34073 | Also, registering whole assemblies is usually a good idea--you should almost never be newing anything up, and it's a terrible pain manually registering tens or hundreds of types. On the other hand, I know the feeling of losing control; I felt like that when I was first learning about DI and IoC. | |
Nov 4, 2017 at 18:37 | comment | added | user34073 | Nope. AutoFac will register it as all interfaces it implements. | |
Nov 4, 2017 at 18:36 | comment | added | t3chb0t |
I use As<> because... I saw it in all Autofac examples and I think it's necessary if components implement more then one interface. Registering an entire assembly doesn't sound like a good idea ;-) I like to have everything under control and prefer to put it together myself. I'm using Autofac here because it's a factory method in a library and I didn't want to new everything myself and I don't want to put everything together each time but I like the idea about passing the outer scope to Create . I need to try this out... or even better, I'll create an Autofac-Module that I can register later
|
|
Nov 4, 2017 at 18:26 | history | answered | user34073 | CC BY-SA 3.0 |