trquth / autofac

Automatically exported from code.google.com/p/autofac
Other
0 stars 0 forks source link

Add an IfNotExists registration extension #469

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This was proposed by Jacek as shown in his clone.

https://code.google.com/r/jszumigaj-autofac/

The idea is to prevent duplicate registration from being made, different to 
PreserveExistingDefaults which still adds the registration. e.g.

[Test] public void RegisteredTwoTimesWith_IfNotRegistered_Extension()
{
     var builder = new ContainerBuilder();
     builder.RegisterType<A1>();
     builder.RegisterType<A1>().IfNotExists(); //registers only if A1 is not registered
     var container = builder.Build();

    var instances = container.Resolve<IEnumerable<A1>>(); //without my extensions we'll get 2 instances here

    Assert.That(instances.Count(), Is.EqualTo(1)); // but we get only one!
}

The changes look good but do break the existing API, and such I suggest we 
leave this for the 4.0 milestone. There is already work that needs to be done 
for PreserveExistingDefaults in regards to its behaviour in nested lifetime 
scopes.

https://code.google.com/p/autofac/issues/detail?id=272

Perhaps we should consider introducing a single Enum to describe the different 
override behaviours?

Original issue reported on code.google.com by alex.meyergleaves on 12 Nov 2013 at 12:37

GoogleCodeExporter commented 8 years ago

Original comment by travis.illig on 14 Nov 2013 at 4:29

GoogleCodeExporter commented 8 years ago

Original comment by travis.illig on 14 Nov 2013 at 5:48

GoogleCodeExporter commented 8 years ago
Moved issue to GitHub: https://github.com/autofac/Autofac/issues/469

Subsequent issue management will be held there; closing the issue on Google 
Code as "WontFix" because we will handle issue resolution on GitHub.

Original comment by travis.illig on 11 Feb 2014 at 12:02