inversion-of-control

Castle windsor instances are registered as singleton even though explicitly declare per web request

孤者浪人 提交于 2019-12-24 15:43:14
问题 I am explicitly declaring my registerations as per web request lifecycle but they are still singletons. this is a problem because my command handlers depend on an IDbConnection which is also registered per web request. here is my registration code: container.Register( Classes .FromAssemblyContaining<EcruiterCommands>() .BasedOn(typeof (ICommandHandler<>)) .WithService.AllInterfaces() .LifestylePerWebRequest()); 回答1: I found the issue, the culprit is this line: .BasedOn(typeof (ICommandHandler

Can I inject properties to third-party beans?

倖福魔咒の 提交于 2019-12-24 15:27:37
问题 Suppose I have classes, which were instantiated not by Spring. For example, they can be instantiated by deserializer or by JavaFX . Can I code these classes in the same way I code Spring beans and inject properties into them later? Actually, I would like a routine, which would scan class with reflection, find all @Autowired annotations in it and inject values from application context? Will this happen, if I call applicationContext.getBeanFactory().registerSingleton("myName", myBean) ? Note,

Using IoC to resolve model objects in Action Methods

别等时光非礼了梦想. 提交于 2019-12-24 15:06:51
问题 I'm using IoC container for dependency injection in Asp.Net MVC 3 and everything seems perfect until I started to write Action methods in my controller. What is the best way to create entity/model objects within the action methods? Sometimes models are retrieved from certain repository or service which are injected to the controller via the constructor, but its not the case with many other model objects in the system. 回答1: An IOC container is best used for creating components; but it shouldn

MissingMethodException - Caliburn

十年热恋 提交于 2019-12-24 13:09:52
问题 I have created a program that uses plugins using Caliburn and .NET 4. When creating an instance of the plugin, a container, window manager, and a view-model factory is injected using caliburn's abilities. However, when a code containing usage of one of the injected properties is run, I get a MissingMethodException . It is driving me crazy. Also, if the plugin instance has dependencies that need to be satisfied (like IContainer, and IWindowManager) which are registered by default in Caliburn,

Can't get Spring to inject my dependencies

可紊 提交于 2019-12-24 12:10:09
问题 I've been trying to get Spring to inject an @Autowired dependency into my application without avail. What am I doing wrong? I created a bean called TimeService. Its job is to return the current time to anyone that asks. package com.foxbomb.springtest.domain.time; import java.util.Date; import org.springframework.stereotype.Service; @Service public class TimeService { public TimeService() { super(); System.out.println("Instantiating TimeService..."); } public Date getTime() { return new Date()

Ioc/DI - Why do I have to reference all layers/assemblies in application's entry point?

纵然是瞬间 提交于 2019-12-24 10:47:13
问题 (Related to this question, EF4: Why does proxy creation have to be enabled when lazy loading is enabled?). I'm new to DI, so bear with me. I understand that the container is in charge of instantiating all of my registered types but in order to do so it requires a reference to all of the DLLs in my solution and their references. If I weren't using a DI container, I wouldn't have to reference the EntityFramework library in my MVC3 app, only my business layer, which would reference my DAL/Repo

Ninject bind mulitple implementations to an interface

旧城冷巷雨未停 提交于 2019-12-24 09:26:19
问题 I'm looking at this tutorial, but not quite understanding how to create a factory that can provide me separate implementations of an interface. http://stefanoricciardi.com/2011/01/21/ninject-mini-tutorial-part-1/ public class IJob { ... } public class JobImpl1 : IJob { ... } public class JobImpl2 : IJob { ... } using (IKernel kernel = new StandardKernel()) { kernel.Bind<IJob>().To<JobImpl2>(); var job = kernel.Get<IJob>(); } My goal is to make a factory class that wraps this Ninject Kernel so

Resolve instances by key and auto-registration with SimpleInjector

微笑、不失礼 提交于 2019-12-24 07:48:28
问题 I'm trying to resolve instances by key with SimpleInjector. In my case, the keys are strings which are coming from a configuration file, and I need the factory to return the correct type based on the string. I used a similar solution like the one described in the link above, but changed it slightly, so the instances can provide their own keys. (there will be many classes that implement IFoo , so I'd like to auto-register them with their keys) Here is the complete working example (.NET Core

Resolve instances by key and auto-registration with SimpleInjector

牧云@^-^@ 提交于 2019-12-24 07:48:25
问题 I'm trying to resolve instances by key with SimpleInjector. In my case, the keys are strings which are coming from a configuration file, and I need the factory to return the correct type based on the string. I used a similar solution like the one described in the link above, but changed it slightly, so the instances can provide their own keys. (there will be many classes that implement IFoo , so I'd like to auto-register them with their keys) Here is the complete working example (.NET Core

Every interface explicitly implemented? (IoC involved) [closed]

风格不统一 提交于 2019-12-24 04:41:09
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I'm very aware of the fact that such a question has probably been posted already. Yet with the involvement of IoC in this case and a lot of code I've seen a colleague in a company I'm new in made this question arise. Scenario: In the codebase of one product this colleague