inversion-of-control

servicestack with funq - autowiring by convention

那年仲夏 提交于 2019-12-09 11:44:56
问题 I have a service which takes an IMyDependency in its constructor. IMyDependency, MyDependency and the service all live in the same assembly. MyDependency has a single, public, parameterless constructor. To my surprise, this did not work: container.RegisterAutoWired<IMyDependency>(); It throws a "System.NullReferenceException". It works if I do this: container.RegisterAutoWiredAs<MyDependency, IMyDependency>(); But then, so does this: container.RegisterAs<MyDependency, IMyDependency>(); So

Get new instance of a spring bean

半世苍凉 提交于 2019-12-09 10:43:27
问题 I have an interface called MyInterface . The class that implements MyInterface (lets call it MyImplClass ) also implements the Runnable interface so i can use it to instantiate threads. This is my code now. for (OtherClass obj : someList) { MyInterface myInter = new MyImplClass(obj); Thread t = new Thread(myInter); t.start(); } What i want to do is to declare the implementing class in my ApplicationContext.xml and get a new instance for each iteration. So my code will look something like this

Dependency Injection composition root and decorator pattern

雨燕双飞 提交于 2019-12-09 08:28:29
问题 I'm getting StackoverflowException 's in my implementation of the decorator pattern when using dependency injection. I think it is because I'm "missing" something from my understanding of DI/IoC. For example, I currently have CustomerService and CustomerServiceLoggingDecorator . Both classes implement ICustomerService , and all the decorator class does is use an injected ICustomerService but adds some simple NLog logging so that I can use logging without affecting the code in CustomerService

Dependency Injection Initialization

我的梦境 提交于 2019-12-09 07:18:26
问题 Please note: I have just started using AutoFac to learn about DI and IoC. Is dependency injection supposed to be initialized in the controllers constructor? How is this? private IMyService iMyService; public HomeController(IMyServices myService) { iMyService = myService; } Different from... public IMyService iMyService = new MyService(); Lastly, it seems like the dependency still exists. Edit: Fixed typo, new MyService(); was new IMyService(); 回答1: Dependency Injection means exactly injection

Does an IoC container replace the use of Factories

风流意气都作罢 提交于 2019-12-09 05:25:25
问题 I am just getting started with IoC containers so apologies if this is a stupid question. I have code like the following in an app internal static class StaticDataHandlerFactory { public static IStaticDataHandler CreateHandler(StaticDataUpdate staticDataUpdate) { if (staticDataUpdate.Item is StaticDataUpdateOffice) { return new OfficeUpdateHandler(); } if (staticDataUpdate.Item is StaticDataUpdateEmployee) { return new EmployeeUpdateHandler(); } if (staticDataUpdate.Item == null) { throw new

What is the use of an IoC framework in an MVC application? [closed]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 05:23:01
问题 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 . I'm trying to understand the use of an IoC framework like StructureMap, but i can't help thinking that these "design patterns" are

What conventions/idioms/patterns are you using configuring IOC Containers using the new Fluent Interfaces

被刻印的时光 ゝ 提交于 2019-12-09 04:53:27
问题 I am in the middle of moving over a large body of code to Castle Trunk which includes the new fluent interface for configuring the container. Since the project has a huge windsorConfig xml file that is beyond maintainable, I thought I would start to take advantage of this new feature. I know other containers (e.g. StructureMap 2.0) also contain fluent interfaces for container configuration, so this question isn't based around Windsor. My question is what conventions/idioms/patterns are you

Can anyone explain to me, at length, how to use IOC containers?

99封情书 提交于 2019-12-09 04:41:00
问题 I use dependency injection through parameters and constructors extensively. I understand the principle to this degree and am happy with it. On my large projects, I end up with too many dependencies being injected (anything hitting double figures feels to big - I like the term 'macaroni code'). As such, I have been considering IOC containers. I have read a few articles on them and so far I have failed to see the benefit. I can see how it assists in sending groups of related objects or in

Best way of injecting application configuration

大城市里の小女人 提交于 2019-12-09 02:59:29
问题 Well, I'm making my foray into this fantastic site with a question about the correct way to inject configuration settings into application components. So, the overview is : I have an application written in C# .Net 3.5. It consists of 3 assemblies - a Core, a Data and a Service. The data & service assemblies require settings retrieved from the app.config, which is done via a settings file, eg. Code : public static String RequestQueueConnectionString { get { return ConnectionSettings.Default

How to handle constructor exception when using Autofac WcfIntegration

本秂侑毒 提交于 2019-12-08 18:41:51
问题 Is there a way to handle an exception thrown by the constructor of a WCF service, when that constructor takes in a dependency, and it is the instantiation of the dependency by the IoC container (AutoFac in this case) that causes the exception ? Consider a WCF service with the following constructor: public InformationService(IInformationRetriever informationRetriever) { _informationRetriever = informationRetriever; } //... the service later makes use of the injected InformationRetriever The