ninject

Dependency Injection: How to configure interface bindings for wrapping

三世轮回 提交于 2019-12-12 10:58:43
问题 So, let's say I have an interface IThingFactory : public interface IThingFactory { Thing GetThing(int thingId); } Now, let's say I have a concrete implementation that retrieves Thing s from a database. Now, let's also say I have a concrete implementation that wraps an existing IThingFactory and checks for a Thing 's presence in, say, an in-memory cache before hitting the wrapped IThingFactory . Something like: public class CachedThingFactory : IThingFactory { private IThingFactory _wrapped;

How do I manage object disposal when I use IoC?

﹥>﹥吖頭↗ 提交于 2019-12-12 10:53:28
问题 My case it is Ninject 2. // normal explicit dispose using (var dc = new EFContext) { } But sometimes I need to keep the context longer or between function calls. So I want to control this behavior through IoC scope. // if i use this way. how do i make sure object is disposed. var dc = ninject.Get<IContext>() // i cannot use this since the scope can change to singleton. right ?? using (var dc = ninject.Get<IContext>()) { } Sample scopes Container.Bind<IContext>().To<EFContext>()

What's the proper way to configure Ninject for an MVC3 application?

牧云@^-^@ 提交于 2019-12-12 10:43:43
问题 I've read several articles regarding the setup of Ninject for MVC3 projects. Some say that your Global.asax.cs should inherit from NinjectHttpApplication , others register modules when constructing the StandardKernel via Application_Start(). I personally used NuGet and it went a different way creating a AppStart_NinjectMVC3 class, and starting it up using [assembly: WebActivator.PreApplicationStartMethod(typeof(MyApp.AppStart_NinjectMVC3), "Start")] Are there any advantages/disadvantages to

Randomly-Occurring Ninject Exception: “Error loading Ninject component ICache”

穿精又带淫゛_ 提交于 2019-12-12 10:38:47
问题 I recently added both Ninject and Ninject.Web.Mvc to an existing ASP.NET MVC 4 web application. When browsing the site, I receive the following exception, seemingly at random: [InvalidOperationException: Error loading Ninject component ICache No such component has been registered in the kernel's component container. Suggestions: 1) If you have created a custom subclass for KernelBase, ensure that you have properly implemented the AddComponents() method. 2) Ensure that you have not removed the

How to use Ninject to inject services into an authorization filter?

情到浓时终转凉″ 提交于 2019-12-12 08:46:42
问题 I am using asp.net mvc 3, ninject 2.0 and the ninject mvc 3 plugin. I am wondering how do I get service layers into my filter(in this case an authorization filter?). I like to do constructor inject so is this possible or do I have to property inject? Thanks Edit I have this for property inject but my property is always null [Inject] public IAccountService AccountServiceHelper { get; set; } protected override bool AuthorizeCore(HttpContextBase httpContext) { // check if context is set if

Log ninject resolved dependencies application start-up

别说谁变了你拦得住时间么 提交于 2019-12-12 08:08:01
问题 We have started using Ninject version 2 as our IoC container along with the extension for resolving by naming conventions. We are also using log4net for our logging. What I would like is for Ninject to log all the dependencies it has found and what will resolve them to, preferably on the application start-up. I have found the logging extension, but can't find documentation or examples on how to use it to get this. Edit: Since it was requested here is the class that logs the default bindings

Ninject error in WebAPI 2.1 - Make sure that the controller has a parameterless public constructor

杀马特。学长 韩版系。学妹 提交于 2019-12-12 07:44:45
问题 I have the following packages and their dependencies installed in my WebAPI project: Ninject.Web.WebApi Ninject.Web.WebApi.OwinHost I am running this purely as a web-api project. No MVC. When I run my application and send a POST to the AccountController's Register action I get the following error returned: { "message":"An error has occurred.", "exceptionMessage":"An error occurred when trying to create a controller of type 'AccountController'. Make sure that the controller has a parameterless

Ninject and packaging service, infrastructure and data layers

亡梦爱人 提交于 2019-12-12 06:30:54
问题 I am a HUGE fan of ninject. To date however I have only used it for single application injections. I currently want to package up my services infrastructure and data layers that I have created. Basically my infrastructure layer has the contracts for creating the stored procedure Dao's that my services layer needs to pass to the data layer. The data layer does the SP call with the parameters added to the DAO and returns a dataset. All of this works excellently. I use constructor based

ASPNET Identity Caching with Dependency Injection

纵然是瞬间 提交于 2019-12-12 06:22:21
问题 I am using Ninject in an MVC application with ASPNET Identity 2. Log in, log out, updating password etc are all working fine. However if I update the user's name in the database, the ApplicationUserManager seems to be caching the user information. This is the code to register the Identity services: private void RegisterServices() { kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>(); var dbContext = kernel.Get<ApplicationDbContext>(); kernel.Bind<IUserStore

Catel/Ninject: Ninject.ActivationException when resolving IUIVisualizerService

怎甘沉沦 提交于 2019-12-12 05:54:11
问题 when i was trying to resolve the IUIVisualizerService a Ninject.ActivationException came up in Ninject.dll. Can someone help me pls? This code section calls the problem: NinjectDependencyResolver resolver = new NinjectDependencyResolver(); var item = resolver.GetService<IUIVisualizerService>(); Code for Resolver: using System; using System.Collections.Generic; using Catel.Services; using Ninject; using NLog; namespace MS_Modell.Infrastructure { internal class NinjectDependencyResolver {