Releases: unitycontainer/container
5.5.3.353
5.5.2.350
5.5.1.342
This release
This release adds new features and fixes one bug
New features
- IContainerContext - new official UnityContainer face for internal operations
- IRegisterTypeStrategy - new interface allowing strategies to be part of registration and add policies as required.
- SingletonLifetimeManager - new globally unique lifetime manager.
Bug fixes
- #177 - Fixed rare condition where setting type interceptor on registration instead of resolving singleton instantiates new instance for each resolution.
5.5.0.330
5.4.0.318
5.3.2.281
5.3.1.266
5.3.0.254
Due to this bug fix sequence of steps during building of objects has changed. Previously strategies were called in this order:
...
TypeMapping,
Lifetime,
PreCreation,
...
Now Lifetime and TypeMapping where reversed and Lifetime is called first. Here is the modified UnityBuildStage
public enum UnityBuildStage
{
/// <summary>
/// First stage. By default, nothing happens here.
/// </summary>
Setup,
/// <summary>
/// Third stage. lifetime managers are checked here,
/// and if they're available the rest of the pipeline is skipped.
/// </summary>
Lifetime,
/// <summary>
/// Second stage. Type mapping occurs here.
/// </summary>
TypeMapping,
/// <summary>
/// Fourth stage. Reflection over constructors, properties, etc. is
/// performed here.
/// </summary>
PreCreation,
/// <summary>
/// Fifth stage. Instance creation happens here.
/// </summary>
Creation,
/// <summary>
/// Sixth stage. Property sets and method injection happens here.
/// </summary>
Initialization,
/// <summary>
/// Seventh and final stage. By default, nothing happens here.
/// </summary>
PostInitialization
}
This change should not affect casual users of the container. Developers of Extensions that rely on this sequence of stages should verify if the change might have broken the extension.
5.2.1.235
Bug Fix
This release is a part of a fix of longest running Unity bug (almost a feature now). The problem it addresses is with registrations affecting each other when new registration is the same Type as previously registered mapping.
Following code explains the problem:
IUnityContainer uc = new UnityContainer();
uc.RegisterType<ILogger, MockLogger>(new ContainerControlledLifetimeManager());
ILogger logger = uc.Resolve<ILogger>();
Assert.IsNotNull(logger);
Assert.AreSame(uc.Resolve<ILogger>(), logger); <-- Resolves Singleton as it should
uc.RegisterType<MockLogger>(new TransientLifetimeManager()); <-- Here is the problem
Assert.AreSame(uc.Resolve<ILogger>(), logger); <-- Resolves new MockLogger and fails
The issue is described here
Impact on existing code
To demonstrate impact on existing code please look at this example:
container.RegisterType<ISomething, Something>(new ContainerControlledLifetimeManager());
var a = container.Resolve<Something>();
var b = container.Resolve<ISomething>();
Assert.AreNotSame(a, b);
Due to the this bug resolving a and b returned the same result because ContainerControlledLifetimeManager
would be applied to ToType
instead of FromType
as it should. In other words it would be applied to Something
instead of ISomething
.
This fix corrects this behavior so only ISomething
(FromType
) registers with ContainerControlledLifetimeManager
and resolution of Something
type will use transient manager.
You could revert back to previous Unity behavior (before this bug fix) by simply registering mapped type with proper lifetime manager:
container.RegisterType<Something>(new ContainerControlledLifetimeManager());
For more information see: #35, 163, #164, #165, #170, #177
More strict use of InjectionFactory
This form of registration used to work for registering interface with InjectionFactory
but it is no longer allowed.
RegisterType<IService, Service>(new InjectionFactory(c => new Service()));
As written, this code registers both: a mapping between IService
and Service
and between IService
and InjectionFactory
. These two are mutually exclusive and create ambiguity which Unity can not resolve.
It should be either one of these but not both:
RegisterType<IService, Service>();
RegisterType<IService>(new InjectionFactory(c => new Service()));
For more information see: #38
5.2.0.216
Minor speed improvement
This is potentially a breaking change so minor version has been increased.
Combined HierarchicalLifetimeStrategy
and LifetimeStrategy
into one step to eliminate one iteration in strategy chain and improve speed of objects creation. All logic is concentrated in uniform LifetimeStrategy
class.