ninject

How to use Ninject bootstrapper in WebApi OwinHost Startup?

江枫思渺然 提交于 2019-12-02 19:13:56
I am migrating from IIS WebAPI to OwinHost. Utilizing the latest pre-release versions of nuget packages, I successfully used instructions here: https://github.com/ninject/Ninject.Web.Common/wiki/Setting-up-a-OWIN-WebApi-application Here is stub of my code: public void Configuration(IAppBuilder app) { var config = new HttpConfiguration(); config.MapHttpAttributeRoutes(); app.UseNinjectMiddleware(CreateKernel); app.UseNinjectWebApi(config); } private static StandardKernel CreateKernel() { var kernel = new StandardKernel(); kernel.Load(Assembly.GetExecutingAssembly()); RegisterServices(kernel);

Ninject. Strange intercept to inner set-properties

安稳与你 提交于 2019-12-02 18:10:11
问题 Domain object: TargetObject.cs public class TargetObject { public virtual ChildTargetObject ChildTargetObject { get { return ChildTargetObjectInner; } set { ChildTargetObjectInner = value; } } public virtual ChildTargetObject ChildTargetObjectInner { get; set; } } Configuration and test: var settings = new NinjectSettings { InjectNonPublic = true, AllowNullInjection = true }; var kernel = new StandardKernel(settings); kernel.Bind<TargetObject>().ToSelf(); kernel.InterceptReplaceSet

Is this right to inject the container/kernel to the main application presenter? [duplicate]

风格不统一 提交于 2019-12-02 18:01:35
问题 This question already has answers here : Is it better to create a singleton to access unity container or pass it through the application? [closed] (4 answers) Closed 5 years ago . I'm using Ninject to handle my dependencies. My ApplicationPresenter is responsible to dispatch the user calls to features throughout the application, hence the need to inject multiple factories at once, thus the container itself. It handles an MDI GUI. Is there a better approach? Is it okay to make it so?

ASP.NET MVC + Ninject: InRequestScope

家住魔仙堡 提交于 2019-12-02 17:18:06
问题 I want to create instance of PerRequestResourceProvider using ninject InRequestScope: public class PerRequestResourceProvider: IPerRequestResourceProvider { priavte readonly _perRequestResorceInstance; public PerRequestResourceProvider() { _perRequestResorceInstance = new PerRequestResource(); } public PerRequestResource GetResource() { return _perRequestResorceInstance; } } public interface IPerRequestResourceProvider { PerRequestResource GetResource(); } In my NinjectDependencyResolver: ...

Loading modules in all assemblies in Ninject

大城市里の小女人 提交于 2019-12-02 16:50:11
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? Abdul Munim 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 yet. This happens because List<INinjectModule> may not in the right order. If you think this is

Dependency injecting UserStore in OWIN startup using Ninject OWIN middleware

大兔子大兔子 提交于 2019-12-02 15:30:00
I am having problems creating a custom UserStore using dependency injection when creating an ApplicationUserManager using the OWIN request pipeline. Background I am trying to migrate the user functionality in our web application from using the SimpleMembership to the new ASP.NET Identity. When starting a new MVC 5 project, the default implementation of the single page application uses ASP.Identity, using Entity Framework to implement the UserStore functionality. In my case, we are already using NHibernate as the ORM, and using ninject to implement the unit of work pattern so that we had one

ASP.NET MVC 3 Application using Ninject, Entity Framework 4 Code-First CTP 5, Patterns

一笑奈何 提交于 2019-12-02 14:44:34
I've tried to build some base project with above technologies. I wanted maximum flexibility and testability so I tried to use patterns along the way to make this as a base for future projects. However, it seem something is wrong or whatever and I really need help here. So i have two questions : Is there anything wrong with my current code? I've applied patterns correctly? Any suggestions or recommendation that would lead me in the right direction? Why do this code actually connect to the database, create it, but doesn't support insert even if I perform the corrects operation? (Look at the end

NInject: Where do you keep your reference to the Kernel?

柔情痞子 提交于 2019-12-02 14:36:46
I'm using NInject on a new web application and there are two things that are unclear to me: Don't I need to keep a reference to the Kernel around (Session/App variable) to insure that GC doesn't collect all my instances? For example, if I specify .Using() and then the Kernel object gets collected, aren't all my "singletons" collected as well? If I do need keep a reference to a Kernel object around, how do I allow the arguments passed in to WithArguments() to change or is that not possible. It's true that you don't want to pass around the kernel. Typically, in a web app, I store the kernel in a

Dependency Injection in WinForms using Ninject and Entity Framework

假如想象 提交于 2019-12-02 14:32:24
I am currently working on a project where we are converting our old DataSet, Stored Procedure WinForm application to use Entity Framework so new websites can access the same object model and repositories. Anyway, I am trying to implement Dependency Injection into the Forms so that we can use mocked Repositories for unit testing. I am using Ninject for the the simple reason I have used it before in MVC websites, however trying to implement this in the WinForm application is proving to be problematic to say the least, hampered even more by the lack of information on DI in WinForms on the web. So

Ninject vs Unity for DI [closed]

≯℡__Kan透↙ 提交于 2019-12-02 14:05:42
We are using ASP.net MVC. Which of these is the best DI framework Ninject or Unity and why? Last time I looked at either of them I found Ninject slightly better. But both have their drawbacks. Ninject has a better fluent-configuration scheme. Unity seems to rely mostly on XML configuration. Ninject's main drawback is that it requires you to reference Ninject.Core everywhere in your code to add [Inject] attributes. If I may ask, why are you limiting your choices to these two? I think Castle.Windsor, Autofac and StructureMap are at least as good or better. roberocity I know this is an old