inversion-of-control

Change spring bean alias with System property

梦想的初衷 提交于 2019-12-06 04:58:12
I try to figure out whether it's possible to change a spring alias configuration through a system property. That's the configuration: <beans> <bean id="beanOne" ... /> <bean id="beanTwo" ... /> <bean id="beanThree" ... /> <alias name="beanOne" alias="beanToUse" /> <bean id="consumer" ...> <constructor-arg ref="beanToUse" /> </bean> </beans> I'd like to be able to use a JVM property e.g. with -Duse=beanThree to select another bean for the alias. Unfortunately using the straight forward solution <alias name="#{systemProperties.use}" alias="beanToUse" /> throws a NoSuchBeanDefinitionException

Ninject - The resource cannot be found

半城伤御伤魂 提交于 2019-12-06 04:50:26
问题 I get error The resource cannot be found. When I try to implement Ninject in my MVC-3 application. The problem appears to be coming from Global.asax during CreateKernel() #region Inversion of Control protected override IKernel CreateKernel() { return Container; } static IKernel _container; public static IKernel Container { get { if (_container == null) { _container = new StandardKernel(new SiteModule()); } return _container; } } internal class SiteModule : NinjectModule { public override void

IoC: How to create objects dynamically

女生的网名这么多〃 提交于 2019-12-06 04:39:28
问题 I have a problem to understand how to use IoC in a scenario where I need to create objects dynamically. Lets assume I have this classes: abstract class Field { public Field( ICommandStack commandStack ) {} } abstract class Entity { public readonly Collection<Field> Fields { get; } } class EntityA { public EntityA( ICommandStack commandStack ) { Fields.Add( new StringField( commandStack ) ); } } class EntitiyB { public EntityB( ICommandStack commandStack ) { Fields.Add( new IntField(

StructureMap - Override constructor arguments for a named instance

我是研究僧i 提交于 2019-12-06 03:48:22
问题 Can you override the constructor arguments for a named instance, it seems you can only do it for a default instance. I would like to do: ObjectFactory.With("name").EqualTo("Matt").GetNamedInstance<IActivity>("soccer"); 回答1: GetInstance behaves like GetNamedInstance when used after .With using NUnit.Framework; using NUnit.Framework.SyntaxHelpers; using StructureMap; namespace StructureMapWith { [TestFixture] public class Class1 { public interface IFooParent { IFoo Foo { get; set; } } public

Is Spring session scoped bean saved in HttpSession?

烂漫一生 提交于 2019-12-06 03:45:34
问题 Since I don't have in depth knowledge of spring session scope implementation. Can anyone please tell me if it is wise to use Spring Session scoped beans, where HttpSession object is very crucial. Like a web application where thousands of users access the site simultaneously. Is spring session scoped bean saved in HttpSession object? Or even if HttpSession object only refers to the spring session scoped bean, are we not making session object heavy? How is it different form storing any bean

Alternative to passing IOC container around

夙愿已清 提交于 2019-12-06 03:38:10
I had the following base class with several dependencies: public abstract class ViewModel { private readonly ILoggingService loggingService; public ViewModel( ILoggingService loggingService, ...) { this.loggingService = loggingService; ... } } In my derived class, I don't want to have to repeat all of the parameters in this base class constructor, so I did this: public abstract class ViewModel { private readonly IUnityContainer container; private ILoggingService loggingService; ... public ViewModel(IUnityContainer container) { this.container = container; } public ILoggingService LoggingService

How to reset all instances in IOC Container

你离开我真会死。 提交于 2019-12-06 03:09:14
问题 I have made an C# WPF Application using the MVVM Light framework. My Application uses the ViewModelLocator class to locate the viewmodels during runtime. The ViewModelLocator makes usage of the SimpleIoc class which also comes with the MVVM Light framework. Here is my scenario: The user logs in an can use my application. On logout, i want to dispose/reset/recreate all viewmodel instances to provide a clean environment to the next user. I tried to implement the Cleanup() method in the

When is using IoC appropriate?

混江龙づ霸主 提交于 2019-12-06 02:49:36
问题 I understand what IoC containers are and have been reading up on Structure Map. The technology seems easy enough to use. My question is, what is the appropriate level of granularity for using an IoC container? I see the following possible levels of application for IoC: Break every dependency between all objects - certainly overkill. Break dependencies between all major objects such as domain objects, support classes, and components within subsystems. Use IoC in conjunction with a Facade to

Why would you want Dependency Injection without configuration?

寵の児 提交于 2019-12-06 02:43:10
问题 After reading the nice answers in this question, I watched the screencasts by Justin Etheredge. It all seems very nice, with a minimum of setup you get DI right from your code. Now the question that creeps up to me is: why would you want to use a DI framework that doesn't use configuration files? Isn't that the whole point of using a DI infrastructure so that you can alter the behaviour (the "strategy", so to speak) after building/releasing/whatever the code? Can anyone give me a good use

MVC and dependency injection, forced to use singleton Controller?

久未见 提交于 2019-12-06 02:35:46
I'm working on building a PHP framework that behaves according to MVC principles and utilizes dependency injection. I think I have the front-controller part down; there is a working router that instantiates a controller instance and calls the appropriate action based on the requested URI. Next up is dependency injection. I want to implement a Container that resolves dependencies using reflection. In doing so, I think I'm running into a problem with my controllers. There are a number of what I call "system dependencies" that need to be available to derived controller classes. I haven't actually