inversion-of-control

Unity - Factory via XML

…衆ロ難τιáo~ 提交于 2019-12-10 15:52:12
问题 I am using the Unity framework as IoC container. My Config looks some like this: <unity> <container> <register type="Namespace1.IFoo, FooAsm" mapTo="Namespace2.Bar, BarAsm"> </register> </conainer> I would like to register a container to use a factory method. How do i achive it using the app.config? I am looking for something like this: <unity> <container> <register type="Namespace1.IFoo, FooAsm" factory="Namespace2.Bar, BarAsm" method="create"> </register> </conainer> </unity> Any

Laravel: do facades actually create new objects on calling methods?

喜你入骨 提交于 2019-12-10 15:32:55
问题 I have a demo class normally bound via $this->app->bind('demo', function() { return new Demo(); } An set up a facade protected static function getFacadeAccessor() { return 'demo'; } The class itself looks like this class Demo { private $value1; private $value2; public function setVal1($value) { $this->value1 = $value; } public function setVal2($value) { $this->value2 = $value; } public function getVals() { return 'Val 1: ' . $this->value1 . ' Val 2: ' . $this->value2; } } I was told that if I

Can inversion of control and RAII play together?

醉酒当歌 提交于 2019-12-10 14:24:03
问题 I was just reading up on inversion of control (IOC) and it bothered me that it seems like it makes memory management a pain. Of course it seems ioc is mostly used in garbage collected environments (Net,Java,Scripting), while my concern is in non-gc settings. My concern here is that IOC in a way goes against RAII, as we decouple resource lifetime from object lifetime. Doesn't this added complexity bother anyone else? And the real question, what techniques can be used to make things go smoothly

StructureMap: How to set lifecycle on types connected with ConnectImplementationsToTypesClosing

China☆狼群 提交于 2019-12-10 14:14:50
问题 In my registry I have Scan(scanner => { scanner.AssemblyContainingType<EmailValidation>(); scanner.ConnectImplementationsToTypesClosing(typeof(IValidation<>)); }); What am I supposed to do to define these all as Singletons? Also as an aside to this question, is there any reason to not define everything that is stateless as a singleton object that's registered in StructureMap? 回答1: Kevin's answer is correct for versions 2.5.4 and older. In the current StructureMap trunk (and when 2.5.5+ is

LightInject IoC container throws stackoverflow when resolving type

北城以北 提交于 2019-12-10 13:45:36
问题 When trying out the LightInject IoC container http://www.lightinject.net/ it throws a stackoverflow exception when resolving the type ISomeService: All types are registered in App_Start: container.RegisterAssembly("MyApp*.dll"); And then when I try to resolve it in the controller it fails and throws a stackoverflow exception: public SomeController(ISomeService someService) { _someService = someService; } It also has the same error when using ServiceLocator: ServiceLocator.Current.GetInstance

Grails Dependency Injection Outside of Services?

血红的双手。 提交于 2019-12-10 13:23:07
问题 I have a Grails application that needs to run a strategy that will likely be swapped out over time. I know Spring underlies Grails, so I was wondering if I had access to Spring's IoC container so that I could externalize the actual dependency in an xml file (note: I have never actually done this, but just know of it, so I may be missing something). My goal is to be able to do something like the following: class SchemaUpdateService { public int calculateSomething(){ ApplicationContext ctx =

creating WindsorContainer results in type conversion error

放肆的年华 提交于 2019-12-10 12:18:42
问题 I am trying to following book : Pro ASP.NET MVC Framework by Steven Sanderson... The line container = new WindsorContainer(xi); produces this error: Could not convert from 'DomainModel.Abstract.IPeopleRepository, DomainModel' to System.Type - Maybe type could not be found** public WindsorControllerFactory() { ConfigResource confres = new ConfigResource("castle"); XmlInterpreter xi = new XmlInterpreter(confres); container = new WindsorContainer(xi); // Also register all the controller types as

Unity: pass parameters to custom lifetime constructor, in xml configuration file

南笙酒味 提交于 2019-12-10 11:17:58
问题 I wrote my CustomLifetimeManager like this: public class CustomLifetimeManager <T> : LifetimeManager { private readonly string _arg; public CustomLifetimeManager(string arg) { _arg = arg; } } Now, it works easy configuring the container programmatically, but how add it in configuration file like the following? <type type="myTime" mapTo="myImpl"> <lifetime type="CustomLifetimeManager"/> </type> 回答1: You need to add a second class: A TypeConverter. This class is responsible for taking a string

What's the benefit of Spring xml ioc over Java instantiation? [closed]

醉酒当歌 提交于 2019-12-10 10:45:34
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Ok, this question is gonna get a lot of downvotes... I just saw this question where a guy is facing some issue with spring xml

Spring injection into inner class

柔情痞子 提交于 2019-12-10 10:23:48
问题 Is it possible to inject beans into inner class? For example: @Named public class outer { @Inject private SomeClass inst; // Injected correctly private static class inner { @Inject private AnotherClass instance; // Not being injected ... Edit: The "AnotherClass" is used only by inner class, so I do not want to pollute outer class with it. Additional reason to keep the declaration in the inner class is that I'll have to remove the static modifier from the inner class or add it to the outer