ninject

Ninject with MembershipProvider | RoleProvider

半世苍凉 提交于 2019-11-30 13:54:13
I'm using ninject as my IoC and I wrote a role provider as follows: public class BasicRoleProvider : RoleProvider { private IAuthenticationService authenticationService; public BasicRoleProvider(IAuthenticationService authenticationService) { if (authenticationService == null) throw new ArgumentNullException("authenticationService"); this.authenticationService = authenticationService; } /* Other methods here */ } I read that Provider classes get instantiated before ninject gets to inject the instance. How do I go around this? I currently have this ninject code: Bind<RoleProvider>().To

DI/IoC Container Performance Benchmark Comparison?

萝らか妹 提交于 2019-11-30 13:49:57
问题 I've found some 2008 benchmark results for testing the performance of several of the top .NET DI/IoC containers here. But I haven't been able to find any updated results. Are there any benchmarks out there that compare some of the big IoC containers (StructureMap, Unity, Ninject, Autofac, Castle Windsor, etc.)? 回答1: I would not recommend using performance benchmarks to pick an IoC container. There are many, many more important factors, such as feature set, development roadmap and

Ninject: Bind Constructor Argument to Property of Other Object

浪尽此生 提交于 2019-11-30 13:48:26
问题 I have an IConfig object that contains settings used throughout my application. At the moment, I inject the entire object into the constructor of each object that needs it, as follows: public interface IConfig { string Username { get; } string Password { get; } //... other settings } public class Foo : IFoo { private readonly string username; private readonly string password; public Foo(IConfig config) { this.username = config.Username; this.password = config.Password; } } The downside is

What is the scope of my Ninject injected ObjectContext in my custom MembershipProvider (using Request scope)?

こ雲淡風輕ζ 提交于 2019-11-30 13:25:45
问题 I use Entity Framework 4 and ASP.NET MVC 3. I made a custom membership provider and use Ninject to inject an EFAccountRepository into it (Bound IAccountRepository to EFAccountRepository). This account repository has an ObjectContext injected into it. I also use this repository (and others) in my controllers. For this reason when I bound IContext to my ObjectContext, I set the scope to "per request" so the ObjectContext only lives in one request and is shared between the repositories. I am

Prevent Ninject from calling Initialize multiple times when binding to several interfaces

北城以北 提交于 2019-11-30 12:36:57
问题 We have a concrete singleton service which implements Ninject.IInitializable and 2 interfaces. Problem is that services Initialize-methdod is called 2 times, when only one is desired. We are using .NET 3.5 and Ninject 2.0.0.0. Is there a pattern in Ninject prevent this from happening. Neither of the interfaces implement Ninject.IInitializable . the service class is: public class ConcreteService : IService1, IService2, Ninject.IInitializable { public void Initialize() { // This is called twice

HttpContext.Current null inside async task

寵の児 提交于 2019-11-30 12:18:28
I have a method that uses a repository ( userRepo ): public override Task<IdentityResult> CreateLocalUserAsync(IUser user, string password, CancellationToken cancellationToken) { var task = new Task<IdentityResult>(() => { TUserEntity newUser = new TUserEntity { Id = user.Id, UserName = user.UserName, Password = password }; userRepo.Save(newUser).Flush(); return new IdentityResult(true); }, cancellationToken); task.Start(); return task; } The userRepo object has a dependency that uses HttpContext.Current . Both of these are resolved using ninject InRequestScope . The above method is called

How does Ninject create controller in ASP.NET MVC?

时光总嘲笑我的痴心妄想 提交于 2019-11-30 12:14:56
This may be stupid question, but I am looking at Ninject sources and don't see NInject registering its own controller factory. I also don't see any IControllerFactory class in Ninject.Web.Mvc assembly. Am I missing something? How does Ninject create controller and inject parameters into constructor? Lets say we are looking for "/Task/Index". Ninject MVC applications use now DefaultControllerFactory , the same as non-Ninject applications. DefaultControllerFactory finds type for controller ( TaskController ). DefaultControllerFactory has internal class called DefaultControllerActivator .

How to intercept all the ASP.NET WebApi controller action methods calls with Ninject interception for logging?

霸气de小男生 提交于 2019-11-30 11:03:59
问题 Our company has the need to log certain things each time one of our action methods of our ASP.NET WebApi controllers gets called. Since we use Ninject for the DI right now, we'd like to use it also for this purpose. This is what I have tried so far. I have Ninject, Ninject.Extensions.Interception and Ninject.Extensions.Interception.DynamicProxy installed through NuGet and I have the following module public class InterceptAllModule : InterceptionModule { public override void Load() { Kernel

Which is a good approach to test Ninject bindings?

吃可爱长大的小学妹 提交于 2019-11-30 10:57:27
We use ninject in all our projects, and as you will know, sometimes it becomes hard to test if the kernel would be able to resolve every type at execution time, because sometimes control gets lost when the magnitude of bindings and autobindings (through ninject extensions) is high. So, what I'm asking here is how can I know that my kernel, after loading all modules and bindings, will be able to resolve every type ? Do you do any kind of Unit Test? Or you just make acceptation tests of the application, at execution time? Any suggestion will be great :) Write an integration test that tests the

How To Use Ninject Named Bindings With DependencyResolver and PropertyInjection

∥☆過路亽.° 提交于 2019-11-30 09:59:01
I realize constructor injection is preferred but I'm curious how to use Ninject's contextual 'Named Bindings' when using another form of injection. Specifically how do I do the following when using DependencyResolver or property injection. public MyService([Named("Alpha")] IRepository repository) { this.repository = repository; } ryber You can create a named binding to work on Alpha: Bind<IRepository>().To<AlphaRepository>().Named("Alpha"); then you can specify others like: Bind<IRepository>().To<AnotherRepository>().Named("Beta"); When your example constructor is used you will get the