Thursday, November 17, 2011
Friday, November 11, 2011
Thursday, November 10, 2011
What "injectionMembers" parameters are for?
The overload with the InjectionMember array is used, when you do not provide a configuration file, that the Unity container tells how to create an instance of the given type or if you want to create an instance on another way than defined in the configuration file. The overloads are used, when you want to configure an unity container without an configuration file. An InjectionMember can be an constructor, property or method call. The following code, taken from the Unity help, shows how to use InjectionMembers through the fluent interface of the container.
var container = new UnityContainer(); container.RegisterType
(new InjectionFactory((c) => Customer.NewCustomer())); var newCustomer = container.Resolve (); Console.WriteLine(newCustomer.Name);
I use InjectionFactory when there is no chance to add an injection attribute for a third party class constructor or property. In this case you can create delegate creating an object.
Powered by Blogger.