ninject

Lazy<> Ninject Injection

妖精的绣舞 提交于 2019-11-28 12:11:08
I use ninject framework. In my code I have a Lazy object. I can create an instance, but when I call the value property I got an exception. private Lazy<IPsoriasisReportUserControl> psoriasisReportUserControl; [Inject] public Lazy<IPsoriasisReportUserControl> PsoriasisReportUserControl { get { return psoriasisReportUserControl; } set { psoriasisReportUserControl = value; } } I got The lazily-initialized type does not have a public, parameterless constructor exception because the injection does not inject the method into the constructor. I think I have to write a method to the bind what Creates

Ninject factory create T based on enum

99封情书 提交于 2019-11-28 11:20:58
问题 I want to let Ninject resolve an instance of T based on a specific enum input value. I have read about Ninject's factory extension, but I couldn't find any example having the factory resolve a specific class based on an enum. Each class derives from a base class and that derived class has several, different interfaces that Ninject also has to resolve. For example this is how the interface should look like: public interface IProcessFactory { T Create<T>(ProcessIndex processIndex) where T :

NInject, nHibernate, and auditing in ASP.NET MVC

你说的曾经没有我的故事 提交于 2019-11-28 11:19:27
问题 I am working on an inherited application which makes use of NInject and nHibernate as part of an ASP.NET MVC (C#) application. Currently, I'm looking at a problem with the auditing of modifications. Each entity has ChangedOn/ChangedBy and CreatedOn/CreatedBy fields, which are mapped to database columns. However, these either get filled with the wrong username or no username at all. I think this is because it has been configured in the wrong way, but I don't know enough about nHibernate and

How to set up IIS 7 application pool identity correctly?

你。 提交于 2019-11-28 10:09:35
Having deployed my website to IIS7.5 I found one strange behaviour: when application pool identity is left to be ApplicationPoolIdentity by default (as recommended in IIS Application Pool Identities ), Ninject seems to be ignored, as I get the following error, while creating the very first controller: System.InvalidOperationException: An error occurred when trying to create a controller of type '..MainController'. Make sure that the controller has a parameterless public constructor. ---> System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred. I tried to grant

Ninject + MVC3 is not injecting into controller

对着背影说爱祢 提交于 2019-11-28 09:54:19
I have used the NuGet Ninject MVC3 extension and have been unable to get it to inject into a controller upon request. It doesn't seem to have bound, as MVC is looking for the paramaterless constructor. Here's the stack trace: [MissingMethodException: No parameterless constructor defined for this object.] System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0 System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98 System

Ninject.ActivationException thrown only on first web request (WebAPI 2, OWIN 3, Ninject 3)

[亡魂溺海] 提交于 2019-11-28 09:38:04
I am attempting to create a "barebones" Web API project that uses OWIN middleware, Ninject Depencency Injection, and ultimately to be hosted in IIS. I have followed instructions found in an article, "Befriending ASP.NET Web.API2, OWIN and Ninject," here: http://www.alexzaitzev.pro/2014/11/webapi2-owin-and-ninject.html , except I used an empty Web Application Project, and did not tick the "Include Web API references and folders" when creating the project. When I fire up the new API and make a page request, I get the following Ninject.ActivationException thrown: Server Error in '/' Application.

Ninject injection based on a route data value

风格不统一 提交于 2019-11-28 09:30:20
We've got an ASP.NET MVC application, that has a number of different areas. There are 2 areas that use the same C# classes from our service layer, but target different underlying data. I want these services to get different dependencies based on a value in the route data. It's hard to explain, and I'm paraphrasing my class/area names. To illustrate: When the 'Code' is in the route data, I want to get different dependencies injected to when it is not present. I understand there is the .When() method you can use to do conditional bindings, but I'm not sure how to get the route data from there. I

How to initialize an object using async-await pattern

允我心安 提交于 2019-11-28 09:05:46
I'm trying to follow RAII pattern in my service classes, meaning that when an object is constructed, it is fully initialized. However, I'm facing difficulties with asynchronous APIs. The structure of class in question looks like following class ServiceProvider : IServiceProvider // Is only used through this interface { public int ImportantValue { get; set; } public event EventHandler ImportantValueUpdated; public ServiceProvider(IDependency1 dep1, IDependency2 dep2) { // IDependency1 provide an input value to calculate ImportantValue // IDependency2 provide an async algorithm to calculate

Ninject inject a service interface in a web service

帅比萌擦擦* 提交于 2019-11-28 09:04:40
问题 I have a web service in my project that I use to return json data to ajax calls. Injecting my ClientService works fine on regular pages but how do I get it to work in the Web Service? NinjectWebCommon.cs: private static void RegisterServices(IKernel kernel) { kernel.Bind<IClientService>().To<ClientService>(); } Default.aspx.cs: works! public partial class _Default : System.Web.UI.Page { [Inject] public IClientService clientService { get; set; } MyWebservice.asmx: NullReferenceException

Making Entity framework implement an interface

China☆狼群 提交于 2019-11-28 08:55:11
I want to use IoC with Entity framework and Ninject. I figure I need the Generated Entity classes to implement an interface, ICRUD. There's a walkthrough that shows how to force Entity framework to implement an interface. I followed the directions and my EntityObjectCodeGenerator.cs file indeed shows "ICrud", but doesn't implement the interface. I don't see any subclasses under EntityObjectCodeGenerator.tt as the article says I'm supposed to. I get error 'BugnetMvc.Models.BugNetEntities' does not implement interface member 'BugnetMvc.Services.ICrud.Update()' UPDATE The goal is to create a