ninject

Ninject InRequestScope missing

百般思念 提交于 2019-12-04 22:14:24
Have a couple of questions regarding the latest version (2.2.1.4) of ninject. Was trying to Bind a Linq2sql DataContext to a concrete implementation InRequestScope (in a class library project) Bind<DataContext>().To<MoneywatchDataContext>() but could not find InRequestScope method ended up doing this, Bind<DataContext>().To<MoneywatchDataContext>().InScope(ctx => HttpContext.Current) Just wanted to find out if: If this will behave exactly like the InRequestScope Method. That it will gurantee that when my HTTContext.Current is GC'ed the underlying DataCotext will be disposed as well. Remo Gloor

ASP.NET MVC WebApi: No parameterless constructor defined for this object

时光总嘲笑我的痴心妄想 提交于 2019-12-04 20:15:36
问题 I have an ASP.NET MVC 4 Application that I want to implement Unit of Work Pattern. In my Web Project I have: IocConfig.cs using System.Web.Http; using NinjectMVC.Data; using NinjectMVC.Data.Contracts; using Ninject; namespace NinjectMVC { public class IocConfig { public static void RegisterIoc(HttpConfiguration config) { var kernel = new StandardKernel(); // Ninject IoC // These registrations are "per instance request". // See http://blog.bobcravens.com/2010/03/ninject-life-cycle-management

Will Ninject call dispose and close the NHibernate Isession?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 18:54:34
问题 I'm using ASP.NET MVC 3 with Ninject and NHibernate. When thinking of DI, i think the one who get the resource also makes sure to close it(In this case Ninject should be responsible) But I'm not sure how Ninject works when using InRequestScope. My code is: Bind<ISession>().ToMethod(context => context.Kernel.Get<ISessionFactory>().OpenSession()).InRequestScope(); I open a session and put it in I InRequestScope, but will Ninject take of closing my ISession when it is out of request scope? 回答1:

MVVM Light, Ninject in a mostly notification area application

[亡魂溺海] 提交于 2019-12-04 18:50:58
I need an application architecture advise. I am building a .Net 4 WPF desktop application with notification area icon support. Application has a few windows, that show up on startup, then get closed, and only the Notification Area icon remains. The notification area icon is purely WPF control that I got from this codeproject example. Since my app should remain running even when all the windows are closed, I have set a ShutdownMode="OnExplicitShutdown" in App.xaml. I will describe my idea of an architecture and startup mechanism, and you tell me where I am going wrong and correct me if possible

How can I implement Ninject .InSingletonScope() when using Unity IoC

别来无恙 提交于 2019-12-04 18:44:35
I was using ninject IoC in my application and in particular the following: kernel.Bind<RepositoryFactories>().To<RepositoryFactories>() .InSingletonScope(); I would like to implement this using the Unity IoC but can someone tell me how I can make it the same and also what does it mean "InSingletonScope()" ? The following works but I am worried that it's not being done correctly because of the Singleton that maybe needs to be specified. container.RegisterType<RepositoryFactories, RepositoryFactories>(); Unity uses the concept of LifeTimeManager 's.. it comes with what is essentially a Singleton

How To Properly Configure Ninject.Extensions.Logging.Log4Net in my MVC3 project

只愿长相守 提交于 2019-12-04 18:32:11
问题 I am trying to properly use Ninject to inject log4net logging into my MVC3 application. I am using the Ninject.MVC3 package, so I have the NinjectMVC3 class that automatically extends the App_Start method and contains the RegisterServices method that binds all dependencies. I also have the Ninject.Extensions.Logging.Log4Net package, but I don't know how to use it. I already know how to configure log4net in my web.config, but don't know how to use this extension for DI. I have read all the

Accessing ninject kernel in Application_Start

此生再无相见时 提交于 2019-12-04 17:17:31
问题 I am using Ninject and the MVC3 extension installed with nuget. My kernel setup code is in the App_Start/NinjectMVC3.cs file. Everything works great in controllers, but I can't figure out how to (properly) bind interfaces in the Global.asax.cs MvcApplication code. I ended up using a hack (creating a public NinjectMVC3.GetKernel() method that returns bootstrap.kernel). However, that will be deprecated, and there must be a proper way to do this that I am not seeing. Here is my code: public

Using Ninject with a Windows Service

霸气de小男生 提交于 2019-12-04 16:55:13
问题 Any good examples of using Ninject with a Windows Service? I'm not sure what if any extensions I need. Also, not sure what the Composition Root should be? Any good examples of using Ninject with a Windows service out there? 回答1: A windows service does not differ much from a regular command line application in regard to dependency injection. The straight-forward composition root is your Main method. The way I usually have done it is create the StandardKernel there with a module in which my

Ninject.MockingKernel.Moq security exception

半腔热情 提交于 2019-12-04 16:48:02
I am using Ninject for my IoC container and I'm trying to write some unit tests. I found the Ninject Mocking Kernel so I thought I'd give it a go but I can't get the simplest test to pass. I am missing something and need a little help. Moq.4.0.10827.Final Ninject-2.2.0.0-release-net-4.0 Ninject.MockingKernel-2.2.0.0-release-net-4.0 My unit test... [TestMethod] public void Constructor_CanInitialize() { var kernel = new MoqMockingKernel(); var mock = kernel.Get<IDataRepository>(); <--Error here Assert.IsInstanceOfType(mock, typeof(DataRepository)); } Here is the error... Test method TestFixture

Ninject setup for general repository using Nhibernate

和自甴很熟 提交于 2019-12-04 16:05:02
I'm developing a .NET Web API application using Nhibernate and a generic repository. Now I'm trying to correctly setup dependency injection using Ninject. However, I have some problems with my current configuration: occasionally my NHibernate ISession (in UnitOfWork.cs below) object is either null or already closed when making a request that goes down to the DAL and tries to fetch data from the database. I have not been able to figure out exactly why this happens or what is wrong in my code. I thought my Ninject scoping/binding was somehow incorrect, but cannot get it to work. This is my