简体   繁体   中英

Simple Injector - Partial class injection

How can I configure the injection with partial class??

container.RegisterPerWebRequest<IDataContextAsync, DataBaseContext>();
container.RegisterPerWebRequest<IStoredProcedureContext, DataBaseContext>();

My code:

public partial class DataBaseContext : DataContext
public partial class DataBaseContext : IStoredProcedureContext

Error:

-[Torn Lifestyle] The registration for IStoredProcedureContext maps to the same implementation and lifestyle as the registration for IDataContextAsync does. They both map to DataBaseContext (Web Request). This will cause each registration to resolve to a different instance: each registration will have its own instance during a single Web Request. See the Error property for detailed information about the warnings. Please see https://simpleinjector.org/diagnostics how to fix problems and how to suppress individual warnings.

See here

var container = new Container();
container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

var registration = Lifestyle.Scoped.CreateRegistration<DataBaseContext>(container);
container.AddRegistration(typeof(IStoredProcedureContext), registration);

container.Verify();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM