ninject-2

Is Kernel.Get<T>() threadsafe + good pattern to share the kernel among components

谁说我不能喝 提交于 2020-04-08 09:41:59
问题 Is Kernel.Get() threadsafe? My goal is share an instance of my kernel among all my componenets and they may all very well call Kernel.Get() at the same time on different threads. Is Kernel.Get() thread safe? What is the best pattern to share the application kernel among all application components which are sitting in different dll's? I prefer not to pass an instance of a factory to every component of my application if this makes sense. 回答1: Get is threadsafe but creating new kernel instances

Is Kernel.Get<T>() threadsafe + good pattern to share the kernel among components

风格不统一 提交于 2020-04-08 09:39:07
问题 Is Kernel.Get() threadsafe? My goal is share an instance of my kernel among all my componenets and they may all very well call Kernel.Get() at the same time on different threads. Is Kernel.Get() thread safe? What is the best pattern to share the application kernel among all application components which are sitting in different dll's? I prefer not to pass an instance of a factory to every component of my application if this makes sense. 回答1: Get is threadsafe but creating new kernel instances

How to configure Ninject so that it would inject right instance depending on previously injected instance

时光毁灭记忆、已成空白 提交于 2020-01-13 14:04:38
问题 I can't find right words for my question so i will let my code speak instead. I have Repository: class Repository { public Repository(DbContext ctx) { } } then i have this bindings: Bind<IRepository>().To<Repository>(); Bind<DbContext>().To<UserStoreContext>().When... Bind<DbContext>().To<CentralStoreContext>().When... and then i have class that needs to access both db's class Foo { public Repository(IRepository userRepo, [CentralStoreAttribute]IRepository centralRepo) { } } How should i

How to configure Ninject so that it would inject right instance depending on previously injected instance

人盡茶涼 提交于 2020-01-13 14:02:18
问题 I can't find right words for my question so i will let my code speak instead. I have Repository: class Repository { public Repository(DbContext ctx) { } } then i have this bindings: Bind<IRepository>().To<Repository>(); Bind<DbContext>().To<UserStoreContext>().When... Bind<DbContext>().To<CentralStoreContext>().When... and then i have class that needs to access both db's class Foo { public Repository(IRepository userRepo, [CentralStoreAttribute]IRepository centralRepo) { } } How should i

How does Ninject create controller in ASP.NET MVC?

断了今生、忘了曾经 提交于 2020-01-10 18:24:46
问题 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? 回答1: 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

Ninject - Multiple Classes Using Single Interface (more than one matching bindings are available)

限于喜欢 提交于 2020-01-05 09:33:14
问题 If I have an implementation of Human and Dog class which uses the IPerson interface and HumanFood and DogFood class using the IFood interface. How can I switch from using HumanFood to DogFood and Human to Dog in my main function? Currently the way this is written it is giving me a "more than one matching bindings are available" error. Thanks! public class Bindings : NinjectModule { public override void Load() { this.Bind<IFood>().To<HumanFood>(); this.Bind<IFood>().To<DogFood>(); this.Bind

EF4.0, repositories, and Ninject 2

蓝咒 提交于 2020-01-02 23:35:12
问题 This is in continuation of two ongoing problems I'm facing: Problems trying to attach a new EF4 entity to ObjectContext while its entity collection entities are already attached and EF4.0 - Is there a way to see what entities are attached to what ObjectContext during debugging? I'm using this space to ask another somewhat complicated question, and I don't want to make a huge, ultra long question out of my other threads. So, a quick rundown: I have incoming form data which is bound to a DTO. I

Ninject, passing constructor argument to the kernel

自作多情 提交于 2020-01-02 02:31:32
问题 Here is my problem: I want to pass in one of the values to the constructor every time I request an instance form the kernel. I written some code below to illustrate the problem. The test is not failing so I guess that this works, but it does look pretty ugly. Is there a better, cleaner way to accomplish this with Ninject? Or should I rethink my design? All suggestions are appreciated. [TestFixture] public class Sandbox { [Test] public void Run_Forrest_Run() { using (var kernel = new

Ninject: Shared DI/IoC container

江枫思渺然 提交于 2019-12-24 07:32:10
问题 I want to share the container across various layers in my application. I started creating a static class which initialises the container and register types in the container. public class GeneralDIModule : NinjectModule { public override void Load() { Bind<IDataBroker>().To<DataBroker>().InSingletonScope(); } } public abstract class IoC { private static IKernel _container; public static void Initialize() { _container = new StandardKernel(new GeneralDIModule(), new ViewModelDIModule()); }

Ninject: One interceptor instance per one class instance being intercepted?

陌路散爱 提交于 2019-12-24 00:16:57
问题 I'm currently having a problem, trying to wire up exactly one interceptor instance per one instance of class being intercepted. I'm creating and Advice in the InterceptorRegistrationStrategy and setting the callback to resolve an interceptor from the kernel (it has an injection constructor). Please note that I can only instantiate interceptor in the callback because InterceptorRegistrationStrategy does not have reference to Kernel itself. IAdvice advice = this.AdviceFactory.Create(methodInfo)