ninject

Ninject per session singleton?

倖福魔咒の 提交于 2019-12-03 13:44:28
问题 So I'm trying to introduce the concept of a user to my application and have got my own set of custom login routines etc. working fine. In my module, I'm binding my IUserSession to my implementation and InSingletonScope. Now I suspect this was the case and have been able to prove that this is not the right thing to do, if I try and login with two users against the same site, I get only one set of data. If I implement a MembershipProvider, do I avoid such a restriction. I know that if I

How to test Ninject ConstructorArguments using MOQ objects?

前提是你 提交于 2019-12-03 13:34:34
问题 I have been doing my first Test Driven Development project recently and have been learning Ninject and MOQ. This is my first attempt at all this. I've found the TDD approach has been thought provoking, and Ninject and MOQ have been great. The project I am working on has not particularly been the best fit for Ninject as it is a highly configurable C# program that is designed to test the use of a web service interface. I have broken it up into modules and have interfaces all over the shop, but

Using mvc-mini-profiler with EF 4.0 and Ninject

蓝咒 提交于 2019-12-03 13:12:14
问题 I'm trying to use the new mvc-mini-profiler with my EF4 based app, but I have no idea how to properly get a connection to my destination datasource. Here's as far as I have gotten. Func<IMyContainer> createContainer = () => { var profiler = MiniProfiler.Current; if (profiler != null) { var rootConn = // ???? var conn = ProfiledDbConnection.Get(rootConn); return ObjectContextUtils.CreateObjectContext<MyContainer>(conn); } else { return new MyContainer(); } }; kernel.Bind<IMyContainer>()

Will Ninject call dispose and close the NHibernate Isession?

蓝咒 提交于 2019-12-03 13:04:38
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? If I understand the code correctly the answer is yes. One of the ActivationStrategies used by Ninject is the

Ninject conditional binding based on parameter type

我是研究僧i 提交于 2019-12-03 12:43:42
I'm using a factory to return a datasender: Bind<IDataSenderFactory>() .ToFactory(); public interface IDataSenderFactory { IDataSender CreateDataSender(Connection connection); } I have two different implementations of datasender (WCF and remoting) which take different types: public abstract class Connection { public string ServerName { get; set; } } public class WcfConnection : Connection { // specificProperties etc. } public class RemotingConnection : Connection { // specificProperties etc. } I am trying to use Ninject to bind these specific types of datasender based on the type of Connection

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

旧街凉风 提交于 2019-12-03 12:42:40
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-or-scoping/ kernel.Bind<RepositoryFactories>().To<RepositoryFactories>() .InSingletonScope(); kernel

Injecting HttpContext in Ninject 2

天大地大妈咪最大 提交于 2019-12-03 12:36:26
问题 In my asp.net mvc application I'm using Ninject as a DI framework. My HttpAccountService is used by my controllers to get info from and to cookies. For this I need the HttpContext.Current in the HttpAccountService. As this is a dependency I injected it throught the constructor as such: kernel.Bind<IAccountService>() .To<HttpAccountService>() .InRequestScope() .WithConstructorArgument("context", HttpContext.Current); Sadly this always binds to the same context which makes that after the first

Ninject: Singleton binding syntax?

最后都变了- 提交于 2019-12-03 12:34:42
问题 I'm using Ninject 2.0 for the .Net 3.5 framework. I'm having difficulty with singleton binding. I have a class UserInputReader which implements IInputReader . I only want one instance of this class to ever be created. public class MasterEngineModule : NinjectModule { public override void Load() { // using this line and not the other two makes it work //Bind<IInputReader>().ToMethod(context => new UserInputReader(Constants.DEFAULT_KEY_MAPPING)); Bind<IInputReader>().To<UserInputReader>(); Bind

Ninject MVC3 - bootstrapper throwing “Already Initialized” exception

回眸只為那壹抹淺笑 提交于 2019-12-03 11:32:57
问题 I've created an empty Asp.Net MVC3 project, and used nuget install-package Ninject.MVC3 Without doing anything else (no services registered and not even a controller created) I run the application. The Project breaks on line 22 in NinjectMVC3.cs with the following exception: [InvalidOperationException: Already Initialized!] Ninject.Web.Mvc.Bootstrapper.Initialize(Func`1 createKernelCallback) in c:\Projects\Ninject\Maintenance2.2\ninject.web.mvc\mvc3\src\Ninject.Web.Mvc\Bootstrapper.cs> :58

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

杀马特。学长 韩版系。学妹 提交于 2019-12-03 11:09: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 following articles/posts, but none of them seem to define how to properly setup a project for DI logging.