Diagnostic Warning - Torn Lifestyle¶
Multiple registrations with the same lifestyle map to the same component.
When multiple Registration instances with the same lifestyle map to the same component, the component is said to have a torn lifestyle. The component is considered torn because each Registration instance will have its own cache of the given component, which can potentially result in multiple instances of the component within a single scope. When the registrations are torn the application may be wired incorrectly which could lead to unexpected behavior.
How to Fix Violations¶
Make sure the creation of Registration instances of your custom lifestyle goes through the Lifestyle.CreateRegistration method instead directly to Lifestyle.CreateRegistrationCore.
When to Ignore Warnings¶
This warning most likely signals a bug in a custom Lifestyle implementation, so warnings should typically not be ignored.
The warning can be suppressed on a per-registration basis as follows:
var fooRegistration = container.GetRegistration(typeof(IFoo)).Registration; var barRegistration = container.GetRegistration(typeof(IBar)).Registration; fooRegistration.SuppressDiagnosticWarning(DiagnosticType.TornLifestyle); barRegistration.SuppressDiagnosticWarning(DiagnosticType.TornLifestyle);