ninject

Ninject InRequestScope fallback to InThreadScope

北城余情 提交于 2019-12-19 05:42:40
问题 In my MVC3 project I've setup my kernel to Ninject the Entityframework context on a InRequestScope basis, this works perfect, but I have a background runner that does some workflow management. It fires up a new thread each 5 minutes and I Ninject my dependencies into this thread, If I change the scope to InThreadScipe the Dispose method is fired, but If i change it back to InRequestScope the Dispose method wont fire. Is there a way of fallbacking to InThreadScope if InRequestScope isnt

Ninject scoping for DBContext used in Quartz.Net job

穿精又带淫゛_ 提交于 2019-12-19 03:13:12
问题 What's the best scoping to use for a DbContext implementation that gets instantiated via Ninject dependency resolver during execution of a Quartz.Net job implementation? If I used thread scope, will the same instance of DbContext get served if the same thread in Quartz's thread pool is used to execute the job multiple times? I would like a scope that means I get one (and only one) new instance of the DbContext each time the job is fired. 回答1: Yes, i would advise against using InThreadScope .

MVC 3 Dependency Injection with Ninject 2.2 + Global Action Filter

心已入冬 提交于 2019-12-19 02:45:29
问题 I am trying to use ASP.NET MVC 3 and Ninject 2.2 to inject a logger object into a custom ActionFilterAttribute. I am able to get this to work if I mark each controller with the custom attribute. However I cannot get this to work if I remove the attribute decoration from the controllers and try to use a global action filter. Here is the code: under App_Start - NinjectMVC3.cs using NinjectTest.Abstract; using NinjectTest.Concrete; [assembly: WebActivator.PreApplicationStartMethod(typeof

Inject dependency into DelegatingHandler

…衆ロ難τιáo~ 提交于 2019-12-19 02:03:16
问题 I am new to dependency injection, but happy with Ninject and Ninject.Extensions.Logging to [Inject] my ILogger wherever i need it. However some DelegatingHandlers are spoiling all the fun. public class HttpsHandler : DelegatingHandler { [Inject] public ILogger Logger { get; set; } protected override Task<HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken cancellationToken) { if (!string.Equals(request.RequestUri.Scheme, "https", StringComparison.OrdinalIgnoreCase))

Do I need to register Ninject.OnePerRequestModule with Ninject.Web.MVC 3.0?

天涯浪子 提交于 2019-12-19 01:43:17
问题 I'm using Ninject for DI and the Ninject.MVC3 extension within an MVC4 app, specifically version 3.0.0.6. Reading the documentation on Ninject's wiki, it appears that the lifetime of objects created with InRequestScope are actually controlled by ASP.NET and to properly clean up one should register the OnePerRequest HttpModule. However it looks like this doco is out of date as type="Ninject.OnePerRequestModule"/> cannot be found. On the other hand I read some bits recently that seemed to

Do I need to register Ninject.OnePerRequestModule with Ninject.Web.MVC 3.0?

故事扮演 提交于 2019-12-19 01:42:03
问题 I'm using Ninject for DI and the Ninject.MVC3 extension within an MVC4 app, specifically version 3.0.0.6. Reading the documentation on Ninject's wiki, it appears that the lifetime of objects created with InRequestScope are actually controlled by ASP.NET and to properly clean up one should register the OnePerRequest HttpModule. However it looks like this doco is out of date as type="Ninject.OnePerRequestModule"/> cannot be found. On the other hand I read some bits recently that seemed to

Ninject working with WCF Web API Preview 5

我的未来我决定 提交于 2019-12-18 21:28:09
问题 Can anybody point me in the right direction to get Ninject working with WCF Web API Preview 5? I have it successfully up and running in my ASP.NET MVC 3 project and also in another internal WCF Service using the Ninject.Extensions.Wcf library. However I cannot get it to work when creating a new MVC 3 project and getting the WebApi.All library from NuGet. I have looked at this stackoverflow post Setting up Ninject with the new WCF Web API but cannot get it working which I believe could be to

Using default parameter values with Ninject 3.0

为君一笑 提交于 2019-12-18 19:27:32
问题 I have a class with a constructor having a parameter with a default value. With Ninject 2.2, it would honor the [Optional] attribute and work fine with no binding defined against a constructor declared like so: public EmployeeValidator([Optional] IValidator<PersonName> personNameValidator = null) Since upgrading to Ninject 3.0, construction of this object fails with a message stating that the provider returned null: Test method ValidatorIsolated.Tests.EmployeeValidatorTest

Ninject syntax for “Bind” with multiple arguments

落爺英雄遲暮 提交于 2019-12-18 18:55:08
问题 How I can use multiple parameters in Ninject syntax like following? Bind<IMyRepository>() .To<SqlMyRepository>() .WithConstructorArgument("connectionString", ConfigurationManager.ConnectionStrings["MyDb"].ConnectionString ); What if more than one parameter need to be passed? 回答1: You can chain the calls to WithConstructorArgument : Bind<IMyRepository>() .To<SqlMyRepository>() .WithConstructorArgument("connectionString", ConfigurationManager.ConnectionStrings["MyDb"].ConnectionString)

Using ninject dependecyResolver for both MVC and WebAPI

陌路散爱 提交于 2019-12-18 13:33:06
问题 I have created and MVC 4 web application and decided to use web api in this app. I'm using ninject dependency resolver for MVC web app. and now I want to use this ninject dependency resolver for web api. but the problem raise here mvc IDependencyResolver namespace is: using System.Web.Mvc and web api IDependencyResolver is using System.Web.Http.Dependencies so how can I solve this issue? finally I want something like this: // Use the container and the NinjectDependencyResolver as //