ninject

Inject value into injected dependency

偶尔善良 提交于 2019-11-27 06:51:21
问题 I'm having something like this: class Root { public Root(IDependency dep) {} } class Dependency:IDependency { public Dependency(int val) {} } And I'm trying to obtain a reference to Root using ninject. So i configure it like this var module = new InlineModule(mod => mod.Bind<IDependency>().To<Dependency>()); var kernel = new StandardKernel(module); I'd like to inject into Dependency some 'val' value that is known only at the moment of obtaining the Root reference from ninject. What i'd like

Cyclic dependency with ninject

梦想的初衷 提交于 2019-11-27 06:43:38
问题 I'm trying to figure out correct way how to bind something like this with ninject. interface IMainService { void DoStuff(); } interface IOtherService { void DoSomeMagic(); } abstract class BaseClass { //many stuff here } class MainClass : BaseClass, IMainService { public MainClass(IOtherService s) { } public void DoStuff() { throw new NotImplementedException(); } //do many other things } class OtherClass : IOtherService { public OtherClass(IMainService s) { } public void DoSomeMagic() { throw

How to initialize an object using async-await pattern

余生长醉 提交于 2019-11-27 05:49:37
问题 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

Ninject and MVC3: Dependency injection to action filters

烂漫一生 提交于 2019-11-27 05:29:08
问题 I've found loads of inconclusive articles and questions on how to do property injection on an ActionFilter in ASP.NET MVC3 using Ninject. Could someone give me a clear example please? Here's my custom auth attribute. public class CustomAuthorizeAttribute : AuthorizeAttribute { [Inject] public IService Service { get; set; } [Inject] public IAuthenticationHelper AuthenticationHelper { get; set; } public override void OnAuthorization(AuthorizationContext filterContext) { //My custom code } } I

Using Ninject in a plugin like architecture

空扰寡人 提交于 2019-11-27 05:02:33
问题 I'm learning DI, and made my first project recently. In this project I've implement the repository pattern. I have the interfaces and the concrete implementations. I wonder if is possible to build the implementation of my interfaces as "plugins", dlls that my program will load dynamically. So the program could be improved over time without having to rebuild it, you just place the dll on the "plugins" folder, change settings and voilá! Is this possible? Can Ninject help with this? 回答1: While

Specific down-sides to many-'small'-assemblies?

妖精的绣舞 提交于 2019-11-27 04:22:16
问题 I am planning out some work to introduce Dependency Injection into what is currently a large monolithic library in an attempt to make the library easier to unit-test, easier to understand, and possibly more flexible as a bonus. I have decided to use NInject, and I really like Nate's motto of 'do one thing, do it well' (paraphrased), and it seems to go particularly well within the context of DI. What I have been wondering now, is whether I should split what is currently a single large assembly

Ninject InSingletonScope with Web Api RC

自作多情 提交于 2019-11-27 04:21:08
问题 I'm having some difficulty using Ninject's InSingletonScope binding with Web Api RC. No matter how I create my binding, it looks like perhaps Web Api is handling scope/lifetime instead of Ninject. I've tried a few variations on wiring up Ninject. The most common is identical to the answer here: ASP.NET Web API binding with ninject I've also tried this version: http://www.peterprovost.org/blog/2012/06/19/adding-ninject-to-web-api/ In both, I'm literally creating an out of the box Web Api

ASP.NET MVC 4 + Ninject MVC 3 = No parameterless constructor defined for this object

拈花ヽ惹草 提交于 2019-11-27 03:38:47
UPDATE - Please look at my answer for a link and explanation of the solution to this problem Before we start, I know this is a very common question and I've been using Ninject for many moons without issues, but now it's come up and I can't figure out a fix. Also, no, none of the results on Google and SO so far have helped me. So, consider the following bit of code running on a very, very, very simple prototype ASP.NET MVC 4 project from Visual Studio 2012 on Windows Server 2008 R2: public class DefaultController : Controller { private IGroupPrincipalRepository GroupPrincipalRepository { get;

How to set up IIS 7 application pool identity correctly?

笑着哭i 提交于 2019-11-27 03:24:53
问题 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. --->

Ninject + MVC3 is not injecting into controller

元气小坏坏 提交于 2019-11-27 03:16:25
问题 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