ninject

Constructor with multiple arguments with Ninject

不问归期 提交于 2019-12-03 05:28:47
I am tring to use Ninject as a IoC container but could not understand how to create an instance of a class that has more than 1 parameter in the constructor. Basically I have a service interface for authentication in a PCL library and its implementation in a WP8 project that receives in the constructor the cosumer key, secret and baseAddress: //On PCL project public interface IAuthorizationService { bool Authenticate(); } //On WP8 Project pubilc class MyAuthenticator : IAuthorizationService { public MyAuthenticator(string consumerKey, string consumerSecret, string baseAddress) { ... } public

Using Ninject with Asp.NET Web API Beta ApiController

允我心安 提交于 2019-12-03 05:21:38
问题 I'm stuck. I was using the method outlined here for wcf web api p6 Ninject working with WCF Web API Preview 5, however things are quite a bit different with the mvc implementation in the beta. There is a good article here http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver that talks about building your own custom dependency resolver, however i would like to use the same implementation i'm using for my mvc view controllers...e.g. Ninject. I've tried a few

Ninject per session singleton?

走远了吗. 提交于 2019-12-03 04:41: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 implement a membership provider, I don't have to inject everything, but my login isn't just a username

NInject: how to pass parameters when Get<T>()?

我的未来我决定 提交于 2019-12-03 04:27:18
I'm using the attached image to explain what I meant. I have a few classes managed by NInject. Some of them have a few singleton instances, and others are in transient scope. In the image, blue rectangles are singltons, red are transient. The Processor depends on other classes or instances. I want to get the instance of Processor each time by using kernel.Get. However, each time I want to use different values for the objects used by the Processor. See Action1 and Action2 in the image. The code is not real but just for explanation here. Is there any existing way can meet my needs? Jerry Wang

How to use a factory with Dependecy Injection without resorting to using Service Locator pattern

寵の児 提交于 2019-12-03 03:55:30
I have a GUI application. In it I allow a user to select from a container-provided list of algorithms. Each algorithm will be kicked off as a background task in another view. I need to support multiple instances of this view, and support multiple instances of the same algorithm. That view will also be provided by the container. The algorithm is also stateful. So I have a case where I need to create instances of my view and algorithm and bind them together at runtime. I don't have static binding points for these instances, so I can't use the normal injection facilities (constructor or property

Loading modules in all assemblies in Ninject

佐手、 提交于 2019-12-03 03:19:40
问题 I have couple of class libraries in my project and all are using Ninject IoC container. I wanted to load all the modules in a StandardKernel at one go wherever an INinjectModule is found. So I used: var kernel = new StandardKernel(); kernel.Load(AppDomain.CurrentDomain.GetAssemblies()) But this doesn't work for some reason. Can anyone help? 回答1: Well, this often happens when bindings are declared but other modules are loaded where that module tries to resolve a binding which has not loaded

Using Prism with Ninject

醉酒当歌 提交于 2019-12-03 03:11:33
Is anyone out there using the Prism framework with Ninject instead of Unity? I need some functionality Unity isn't supporting yet, and I've decided to switch the IoC container to Ninject. I'm struggling a bit with the replace though.. What I need to use from Prism is the EventAggregator and the RegionManager. I have seen this sample that actually does the replace, but this is written for an older version of Prism, and several of the classes seems to have changed etc. So I ended up all confused after looking doing some effort in trying to rewrite it. So - my question is basically: How can I

Ninject: Singleton binding syntax?

人走茶凉 提交于 2019-12-03 02:58:43
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<UserInputReader>().ToSelf().InSingletonScope(); } } static void Main(string[] args) { IKernel ninject

Using mvc-mini-profiler with EF 4.0 and Ninject

这一生的挚爱 提交于 2019-12-03 02:35:27
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>().ToMethod(ctx => createContainer()).InRequestScope(); How do I get a connection to an EF container, without

Ninject MVC3 - bootstrapper throwing “Already Initialized” exception

自闭症网瘾萝莉.ら 提交于 2019-12-03 02:04:00
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 Mvc.App_Start.NinjectMVC3.Start() in c:\Projects\Events\Events\App_Start\NinjectMVC3.cs:22