ninject

Ninject Conditional Self bind to change scope (For Task-scheduler) not working properly?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 08:44:16
问题 Within MVC Web Application DbContext binding work properly with InRequestScope() kernel.Bind<DbContext>().ToSelf().InRequestScope(); kernel.Bind<IUnitOfWork<DbContext>>().To<UnitOfWork<DbContext>>(); But from a Task Scheduler call DbContext in InRequestScope() unable to update Db Table ( without any error ), until I change Binding to InSingletonScope() OR InThreadScope() Question: So is their any way change scope to InSingletonScope() / InThreadScope() for a Task Scheduler Call. ? // For Task

Ninject w/ ASMX web service in a MVC3/Ninject 3 environment

帅比萌擦擦* 提交于 2019-11-28 08:41:39
问题 I'm looking for the best way to incorporate a classic asmx web service into my MVC3 environment. I'd like the kernel/container to be shared between the two. In the past with ASP.NET web forms I was able to use the following: [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] public class Service : WebServiceBase { [Inject] public IContextProvider ContextProvider { get; set; } ... This used the older Ninject.Web to shared the kernel using

Ninject Intercept any method with certain attribute?

百般思念 提交于 2019-11-28 08:26:33
How can I get Ninject.Extensions.Interception to basically let me bind a specific interceptor to any method that has an attribute... psudocode: Kernel.Intercept(context => context.Binding.HasAttribute<TransactionAttribute>()) .With<TransactionInterceptor> With a class like: public SomeClass { [TransactionAttribute] public void SomeTransactedMethod() { /*do stuff */ } } Assuming that you are using Ninject.Extensions.Interception this should do the trick public class TransactionInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { // Do something... } } public class

Ninject Scope issue with Tasks/Threads

旧时模样 提交于 2019-11-28 07:27:45
问题 I have an MVC3 project that uses Ninject, Entity Framework and the Unit of Work pattern with a Service layer. My AsyncService class has a function that starts a background task that, as an example, adds users to the User repository. My current problem is that the task only runs correctly for a few seconds before I get an error that the DbContext has been disposed. My database context, which is injected with Ninject's InRequestScope() seems to be getting disposed, as InRequestScope() ties it

Using Dependency Injection in ASP.NET MVC3 Model Binder

為{幸葍}努か 提交于 2019-11-28 07:17:38
问题 I'm working on MVC3 website, trying to use Ninject to resolve my dependencies. I have the following scenario: public class UserModelBinder : IModelBinder { //[Inject] public UserDataService userData { get; set; } public object BindModel( ControllerContext controllerContext, ModelBindingContext bindingContext) { Guid UserID = (Guid)Membership.GetUser().ProviderUserKey; //userDataService = DependencyResolver.Current // .GetService<UserDataService>(); User user = userDataService.GetUser(UserID);

SignalR 2 Dependency Injection with Ninject

大城市里の小女人 提交于 2019-11-28 06:58:44
I have an existing MVC application that is using Dependency Injection with Ninject. I installed the Ninject.MVC3 nuget package and it creates a class called NinjectWebCommon in my App_Start, which completely isolates the kernel and registers all of my bindings: public static void Start() { DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule)); DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule)); bootstrapper.Initialize(CreateKernel); } private static IKernel CreateKernel() { var kernel = new StandardKernel(); kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new

NinjectDependencyResolver fails binding ModelValidatorProvider

落爺英雄遲暮 提交于 2019-11-28 06:49:53
I'm developing an ASP.NET Web Api 2.2 with C#, .NET Framework 4.5.1. After updating my Web.Api to Ninject 3.2.0 I get this error: Error activating ModelValidatorProvider using binding from ModelValidatorProvider to NinjectDefaultModelValidatorProvider A cyclical dependency was detected between the constructors of two services. Activation path: 3) Injection of dependency ModelValidatorProvider into parameter defaultModelValidatorProviders of constructor of type DefaultModelValidatorProviders 2) Injection of dependency DefaultModelValidatorProviders into parameter defaultModelValidatorProviders

WebApi Custom Filter with injected interface in constructor does not get called

自古美人都是妖i 提交于 2019-11-28 06:20:02
问题 My problem statement is same as this question i.e., use an injected service in attribute/filter. I have tried the solution given by B Z and following is my code along the lines of solution given. //marker attribute public class AuthorizeViewAttribute : Attribute { } //filter public class AuthorizeViewFilter : IAuthorizationFilter { private readonly IAccessRightsService _iAccessRightService; public AuthorizeViewFilter(IAccessRightsService iAccessRightService) { _iAccessRightService =

NHibernate, and odd “Session is Closed!” errors

南楼画角 提交于 2019-11-28 05:58:12
Note: Now that I've typed this out, I have to apologize for the super long question, however, I think all the code and information presented here is in some way relevant. Okay, I'm getting odd "Session Is Closed" errors, at random points in my ASP.NET webforms application. Today, however, it's finally happening in the same place over and over again. I am near certain that nothing is disposing or closing the session in my code, as the bits of code that use are well contained away from all other code as you'll see below. I'm also using ninject as my IOC, which may / may not be important. Okay,

Conditional dependency injection binding only when property not null

巧了我就是萌 提交于 2019-11-28 05:57:53
问题 It is a desktop application which is obliged to impersonate the current user when accessing the underlying data source. How can I tell Ninject not to bind the dependency until the property of a parent object is not null? Application forces user authentication upon startup Once authenticated, a reference to the current user credentials is kept within the IMembershipService Accessing the underlying datasource obliges to have a user authenticated so that the commection string states the