Ninject를 사용하여 객체의 수명을 관리하려고합니다. 내 IRepository 객체의 경우 IDisposable을 구현해야하며 ConcreteRepository에서는 NHibernateSession을 종료하기 위해 IDisposable을 구현했습니다.Ninject 3.0에서 InRequestScope로 매핑 된 객체를 처리하지 않습니다.
내 문제는 ConcreteRepository의 인스턴스화 및 파괴/처분 수를 계산하기 위해 ConcreteRepository 내에 정적 변수를 두는 것입니다 ... 응용 프로그램을 실행할 때 데이터베이스 연결이 끊어지고, 내 로그는 내 응용 프로그램이 절대로 내 연결을 해제하지 않는다는 것을 보여줍니다.
내 Global.asax에 :
public class Global : NinjectHttpApplication
{
protected override void OnApplicationStarted()
{
base.OnApplicationStarted();
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
ControllerBuilder.Current.DefaultNamespaces.Add("WebPortal.Controllers");
var log4netConfigFileInfo = new System.IO.FileInfo(Server.MapPath("~/log4net.xml"));
log4net.Config.XmlConfigurator.ConfigureAndWatch(log4netConfigFileInfo);
log4net.ILog log = log4net.LogManager.GetLogger(typeof(Global));
log.Info("Started...");
}
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected override Ninject.IKernel CreateKernel()
{
var kernel = new Ninject.StandardKernel(
new Utils.UtilsModule(),
new Web.DataObjects.NHibernate.DataObjectsNHibernateModule(),
new Payroll.PayrollModule(),
new Web.DataObjects.DbModule()
);
kernel.Load(Assembly.GetExecutingAssembly());
return kernel;
}
}
내가 함께 테스트하는 데 사용하고
내 컨트롤러 모듈 :
public class DatabaseAreaModelModule
: NinjectModule
{
public override void Load()
{
Bind<DiscountEdit>().ToSelf().InRequestScope();
Bind<ItemCategoryEdit>().ToSelf().InRequestScope();
Bind<ItemEdit>().ToSelf().InRequestScope();
Bind<ModifierEdit>().ToSelf().InRequestScope();
Bind<ModifierSetEdit>().ToSelf().InRequestScope();
Bind<RevenueCenterEdit>().ToSelf().InRequestScope();
Bind<RevenueClassEdit>().ToSelf().InRequestScope();
Bind<TaxEdit>().ToSelf().InRequestScope();
}
}
내 "NHibernate에"Ninject에 모듈 :
public class DataObjectsNHibernateModule
: NinjectModule
{
public override void Load()
{
Bind<ISessionFactory>().ToProvider<NHibernateSessionProvider>().InSingletonScope();
Bind<IRepository>().To<NHibernateRepository>().InRequestScope();
}
}
무엇 나는 왜 내가 InRequestScope()이 될 것을 요청할 때 그것이 처분되지 않고 있는지를 알아 내려고 노력하고있다. 어떤 아이디어라도?
와 함께 웹 확장 중 하나를로드하지 않았습니다. http://vault13.co.uk/ninject-mvc3-and-web-requests/ –