This project is read-only.

Should the container warn about registrations for the same implementation with different lifestyles?

Mar 10, 2015 at 10:36 PM
Currently the container warns if multiple registrations have been made for the same implementation (with different service types) for the same lifestyle, because this might accidentally cause multiple instances where the user might expect just one instance in a certain scope.

But what about the following example:
container.RegisterSingle<IFoo, FooBar>();
container.Register<IBar, FooBar>();
Should the container warn about this? When would this be okay, and when would this be an error?
Mar 11, 2015 at 5:01 PM
Edited Mar 11, 2015 at 5:03 PM
Yes the container should warn about this.

I think it is better you show false positives than to think for the user if he has a use case where this would be acceptable. Offcourse the number of false positives must be kept to a minimum. Otherwise users will dismiss all info giving by the diagnostic services. But in this case I think it's worth a false positive.

Looking into the future where warnings can become errors as discussed here this should be taking into account an should be part of the configuration options for throwing this kind of warning as an error.
Mar 11, 2015 at 5:04 PM
Is this the same warning as our current Torn lifestyle, or is this something different? And if so, how should this warning be called?
Mar 11, 2015 at 5:58 PM
Edited Mar 11, 2015 at 6:03 PM
This is the same warning with a different explanation text, IMO.

Allthough the description in the docs says specifically:
with the same lifestyle
I think of the Torn lifestyle warning of a warning when a single component (= specific implementation) has multiple registrations which can result in different instances with the same or even different lifestyles.
Mar 11, 2015 at 8:29 PM
This discussion is related to this work item.