ninject

Multitenancy with Fluent nHibernate and Ninject. One Database per Tenant

放肆的年华 提交于 2019-11-30 04:24:07
I'm building a multi-tenant web application where for security concerns, we need to have one instance of the database per tenant. So I have a MainDB for authentication and many ClientDB for application data. I am using Asp.net MVC with Ninject and Fluent nHibernate. I have already setup my SessionFactory/Session/Repositories using Ninject and Fluent nHibernate in a Ninject Module at the start of the application. My sessions are PerRequestScope, as are repositories. My problem is now I need to instanciate a SessionFactory (SingletonScope) instance for each of my tenants whenever one of them

Lazy Dependency Injection

只愿长相守 提交于 2019-11-30 03:53:32
I have a project where the Ninject is used as IoC container. My concern is that a lot of classes have such kind of constructors: [Inject] public HomeController( UserManager userManager, RoleManager roleManager, BlahblahManager blahblahManager) { _userManager = userManager; _roleManager = roleManager; _blahblahManager = blahblahManager; } What if I don't want to have all instances of these classes at once? The way, when all this classes are wrapped by Lazy<T> and passed to constructor is not exactly what I need. The T instances are not created yet, but Lazy<T> instances are already stored in

Ninject - how and when to inject

邮差的信 提交于 2019-11-30 03:18:06
I'm a newbie when it comes to DI and ninject and I'm struggling a bit about when the actual injection should happen and how to start the binding. I'm using it already in my web application and it working fine there, but now I want to use injection in a class library. Say I have a class like this: public class TestClass { [Inject] public IRoleRepository RoleRepository { get; set; } [Inject] public ISiteRepository SiteRepository { get; set; } [Inject] public IUserRepository UserRepository { get; set; } private readonly string _fileName; public TestClass(string fileName) { _fileName = fileName; }

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

巧了我就是萌 提交于 2019-11-30 03:12:42
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! } } And module looks like this: public class ServiceModule : NinjectModule { public override void

Injecting dependencies into an IErrorHandler implementation

淺唱寂寞╮ 提交于 2019-11-30 02:56:47
问题 I am implementing IErrorHandler in order to centralize all of the error handling for my WCF service in one place. This works fairly well: public class ServiceErrorHandler : IErrorHandler { public bool HandleError(Exception error) { // ..Log.. } public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { // ..Provide fault.. } } Now, we're using Ninject to inject dependencies in the rest of the service, and I'd like to do the same here. Since WCF is constructing the

Error “More than one matching bindings are available” when using Ninject.Web.Mvc 2.0 and ASP.NET MVC 1.0

谁说胖子不能爱 提交于 2019-11-30 02:53:08
Recently I've switched to Ninject 2.0 release and started getting the following error: Error occured: Error activating SomeController More than one matching bindings are available. Activation path: 1) Request for SomeController Suggestions: 1) Ensure that you have defined a binding for SomeController only once. However, I'm unable to find certain reproduction path. Sometimes it occurs, sometimes it does not. I'm using NinjectHttpApplication for automatic controllers injection. Controllers are defined in separate assembly: public class App : NinjectHttpApplication { protected override IKernel

Usage of binding to constants and binding to types in scopes with Ninject

女生的网名这么多〃 提交于 2019-11-30 02:41:38
问题 Which way of creating bindings of single object to interface is preferable, when and why: Kernel.Bind<IFoo>().ToConstant(new Foo()); or Kernel.Bind<IFoo>().To(typeof(Foo)).InSingletonScope(); Or, if both ways are incorrect and better to be avoided, what should be used instead? 回答1: With both constructions you accomplish the same. However, in the latter approach construction of the single Foo object is deferred until the first Get call. Let me illustrate that with a little example. Consider

Where to locate Ninject modules in a multi-tier application

泪湿孤枕 提交于 2019-11-30 02:36:35
My application includes a number of back-end assemblies (including an Entity Framework data repository layer) that are shared by a number of front-end assemblies (including a Windows service and an MVC3 web application). My understanding of the Ninject binding process is that each assembly that contains injectable types should also contain an Ninject module that defines the default bindings for these types. The set of defined modules would then be loaded into the Ninject Kernel of the consuming assemblies. However, I am running into problems, since the required binding scope is not always

How-to inject the Entity Framework DbContext into the ConfigurationBasedRepository of SharpRepository

喜夏-厌秋 提交于 2019-11-30 01:50:22
I really would like to use SharpRepository together with Ninject , but I do not understand how to configure Ninject to share the Entity Framework DbContext between the repositories. I am using Entity Framework version 5 and Ninject version 3. Currently I am using Ef5Repository in my source code, but I want to replace it with ConfigurationBasedRepository . But I cannot figure out how to pass (or inject) the EF DbContext to the repositories. Example (current state): using SharpRepository.Repository; public interface IProductRepository : IRepository<Product> { } using SharpRepository

Ninject - In what scope DbContext should get binded when RequestScope is meaningless?

China☆狼群 提交于 2019-11-30 01:37:28
问题 In an MVC / WebAPI environment I would use InRequestScope to bind the DbContext . However, I am now on a Console application / Windows service / Azure worker role (doesn't really matter, just there's no Web request scope), which periodically creates a number of Tasks that run asynchronously. I would like each task to have its own DbContext , and since tasks run on their own thread, I tried binding DbContext using InThreadScope . Unfortunately, I realize that the DbContext is not disposed when