You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Patrick Klaeren edited this page Dec 11, 2022
·
3 revisions
Multiple lifetime registration
AutoRegisterInject will not allow multiple lifetime registration on the same type. ARI will select the first registration lifetime it finds on a type to generate the registration statement.
[RegisterScoped,RegisterSingleton]publicclassFoo;
will result in
serviceCollection.AddScoped<Foo>();
Foo will not be registered as singleton. It is the opinion of ARI that this is not a valid scenario and it becomes an output based on first come, first served.
On the contrary, reordering to prioritise RegisterSingleton over RegisterScoped:
[RegisterSingleton,RegisterScoped]publicclassFoo;
will result in
serviceCollection.AddSingleton<Foo>();
Partial class exception
In the unlikely event you do wish to register the same type as multiple lifetimes, Foo can be made partial with each partial declaration having its own registration.