ioc-container

IoC Castle Windsor - No parameterless constructor defined for this object

百般思念 提交于 2019-12-07 02:48:48
问题 I'm getting the 'No parameterless constructor defined for this object' on my controller when the controller and its dependencies are being registered accordingly via (DI/IoC) pattern using Castle Windsor. Can someone take a look at the following and see my error because i can't see it. Code for registration on global.asax public class MyApplication : System.Web.HttpApplication { public MvcApplication() { this.container = new WindsorContainer().Install(new DependencyInstaller()); } protected

Register all autofac modules from assembly by one line

对着背影说爱祢 提交于 2019-12-07 00:26:43
问题 I can register all Autofac modules (classes derived from Autofac.Module) one by one using line like this builder.RegisterModule(new LoggingInjectionModule()); But if I have 10 or more modules I want just to specify assembly, where Autofac can find all modules, that it need to register. Is there is any way to register all modules from specific assembly, namespace by single line or two lines? 回答1: You can use the different overloads (see API doc) of the RegisterAssemblyModules method: builder

Simple Injector pass hard coded values into constructor

痞子三分冷 提交于 2019-12-06 21:56:57
问题 In Simple Injector I can do the following: container.RegisterSingle<IAuctionContext>(() => new AuctionContext( new Uri("http://localhost:60001/AuctionDataService.svc/"))); What I am doing here is saying that when IAuctionContext is found, replace it with this new AuctionContext . The problem is that with the call to RegisterSingle , only a single instance of AuctionContext will be used. What I'd like it to be able to pass in a Uri parameter as above but not have the single instance but allow

Multiple Decorator pattern in castle-windsor

爷,独闯天下 提交于 2019-12-06 18:27:49
问题 We are in the process of redesigning some legacy software to be more testable and have decided upon Dependency-Injection and Castle.Windsor to help us. First, our goal: * A number of decorators that all work on a data stream. * Multiple combinations of the decorators are possible and the root nodes in each case can be required to get data from different places. Technically, our design is as follows: interface IUpdateableValue<T> { T Get(); }; We have e.g. three sets of data to be retrieved

Load objects with parameters from Laravel IoC container

ぃ、小莉子 提交于 2019-12-06 14:53:38
I need a way to load objects via IoC provider depending on a request parameter. Right now I'm loading my objects directly with App::make(xy, [$urlParamter] which I want to refactor, so that I can use dependency injection the way it is supposed to. To describe my current architecture I need to show you quiet some information and in the end you find my concrete questions I have about it. I'm building up a general CMS framework which provides an import architecture that is extendable with a custom import implementation. Now I'm struggling with properly loading the concrete classes via IoC

Chaining layers with IoC, setting lower callback to upper and avoid circular reference

我们两清 提交于 2019-12-06 14:36:07
I have a scenario where I need a lower layer to be controlled by an upper layer much like a puppet master pulling on strings. The lower layer also will call back to the upper layer as some internal events are generated from time to time. I am using SimpleInjector, I inject the ILower in to the Upper constructor. I cannot inject the Upper in to the Lower as it would cause a circular reference. Instead I have a register callback function to link the two layers. However, I have to scatter my code with null checks. Are there any nicer ways or different architectures to achieve this linking of

How do I use Structuremap 3 with objects that aren't friendly to constructor injection?

人盡茶涼 提交于 2019-12-06 11:43:52
I'm moving from StructureMap 2.x to 3.x. One major change is that using ObjectFactory results in the following warning: 'StructureMap.ObjectFactory' is obsolete: 'ObjectFactory will be removed in a future 4.0 release of StructureMap. Favor the usage of the Container class for future work' So in most cases, the resolution is fairly easy: pass through IContainer as a constructor. Unfortunately this is not feasible for ASMX web serivces or attributes, both of which require a default constructor. That means I'm probably stuck with the Service Locator Pattern , property injection, or writing my own

SimpleIoC - Type not found in cache: Windows.UI.Xaml.Controls.Frame

扶醉桌前 提交于 2019-12-06 09:39:20
I am running into the below error the first time my ViewModel is being instantiated by the SimpleIoC. I believe I have setup the container as it should be, but for some reason, I am still getting the below error. Any ideas or assistance would be very much appreciated. Microsoft.Practices.ServiceLocation.ActivationException was unhandled by user code HResult=-2146233088 Message=Type not found in cache: Windows.UI.Xaml.Controls.Frame. Source=GalaSoft.MvvmLight.Extras StackTrace: at GalaSoft.MvvmLight.Ioc.SimpleIoc.DoGetService(Type serviceType, String key) in c:\Users\Public\Downloads\CodePlex

Autofac: Resolve a specific dependency to a named instance

拜拜、爱过 提交于 2019-12-06 09:06:20
问题 Using Autofac, I would like to register a component and specify for a specific dependency to be resolved to a named instance. I found samples like the following using constructor injection which is almost what I want. builder.Register(c => new ObjectContainer(ConnectionStrings.CustomerDB)) .As<IObjectContainer>() .Named("CustomerObjectContainer"); builder.Register(c => new ObjectContainer(ConnectionStrings.FooDB)) .As<IObjectContainer>() .Named("FooObjectContainer"); builder.Register(c => new

IoC and managing interfaces

和自甴很熟 提交于 2019-12-06 08:33:29
Say I had a business object library which was using IoC to implement a data access library. Where should I define the Data Access Interface? Which library does it belong? Or should it be in a separate library just for interfaces? I would define the interfaces within the business domain. Then the implementations of the interfaces would be in a library that references the business domain (and is referenced by whatever the application context is, or by an IoC library which is referenced by the application context). Then swapping out one implementation with another is just a matter of creating