Flexberry UnityFactory is product platform Flexberry and allows a standard way to work with a resolution of containers Unity Container. Use the version of Unity 2.1.
Note: Flexberry UnityFactory is available for installation in the project via the NuGet package Flexberry ORM.
CreateContainer() creates a default container to resolve the interface in real authority:
IUnityContainer container = ICSSoft.Services.UnityFactory.CreateContainer(); IService serviceInstance = container.Resolve<IService>();
Note: the Problem with this method: when you create the instance based on settings are taken into account the lifetime of the object. This setting tells how the container should create the object in question: every time a new, to create a single and priispolzovanii, etc. However, all these settings are working within a particular container instance, and each time CreateContainer creates a new container. This leads to the fact that objects of type singleton (ContainerControlledLifetimeManager) in fact are not.
GetContainer(), returns a single (application domain) of the container instance that allows to work correctly with objects of type
IUnityContainer container = ICSSoft.Services.UnityFactory.GetContainer(); IService serviceInstance = container.Resolve<IService>();
Note: When you use UnityFactory it is recommended to use the method GetContainer().