Mein Fall ist es Ninject 2.Wie verwalte ich die Entsorgung von Objekten, wenn ich IoC verwende?
// normal explicit dispose
using (var dc = new EFContext)
{
}
Aber manchmal brauche ich länger um den Kontext zu halten oder zwischen Funktionsaufrufen. Also ich möchte dieses Verhalten durch IoC-Bereich steuern.
// if i use this way. how do i make sure object is disposed.
var dc = ninject.Get<IContext>()
// i cannot use this since the scope can change to singleton. right ??
using (var dc = ninject.Get<IContext>())
{
}
Beispieltive
Container.Bind<IContext>().To<EFContext>().InSingletonScope();
// OR
Container.Bind<IContext>().To<EFContext>().InRequestScope();
Duplizieren: http://stackoverflow.com/questions/987761/how-do-you-reconcile-idisposable-and-ioc – TrueWill
Danke für den Link – Aval