inversion-of-control

Dependency on Log4Net Logger and Retrieve Logger by Caller Type using Castle Windsor

我是研究僧i 提交于 2019-12-08 07:31:08
问题 I have a thin wrapper around log4net and I am trying to use the type of the calling class to get a logger from log4net.LogManager by using Castle.Windsor . public class Foo: IFoo { private readonly ICommonLog _logger; public Foo(ICommonLog logger) { _logger = logger; } public void FooBar() { _logger.Info("Enter FooBar Method"); } } public class CommonLog : ICommonLog { private readonly log4net.ILog _logger; public CommonLog(Type loggerType) { _logger = log4net.LogManager.GetLogger(loggerType)

Is it possible to create a collections with Spring configuration?

一个人想着一个人 提交于 2019-12-08 06:22:15
问题 Suppose I have a class MyClass which can be instantiated either with String or it have predefined static instances inside a class. Something like this: public class MyClass { public final static MyClass A = new MyClass("A"); public final static MyClass B = new MyClass("B"); public final static MyClass C = new MyClass("C"); ... public MyClass(String name) { ... } } Is it possible to create an ArrayList<MyClass> bean in Spring config somehow? Something like <bean id="sequence" class="..

Make sure that the controller has a parameterless public constructor in web api?

狂风中的少年 提交于 2019-12-08 06:15:24
问题 I am struggling with this problem of dependency injection using untiy . I have implemented according to this link https://www.asp.net/web-api/overview/advanced/dependency-injection But got this error: { "Message": "An error has occurred.", "ExceptionMessage": "An error occurred when trying to create a controller of type 'WebAPIController'. Make sure that the controller has a parameterless public constructor.", "ExceptionType": "System.InvalidOperationException", "StackTrace": " at System.Web

Dependency on Log4Net Logger and Retrieve Logger by Caller Type using Castle Windsor

不问归期 提交于 2019-12-08 05:38:22
I have a thin wrapper around log4net and I am trying to use the type of the calling class to get a logger from log4net.LogManager by using Castle.Windsor . public class Foo: IFoo { private readonly ICommonLog _logger; public Foo(ICommonLog logger) { _logger = logger; } public void FooBar() { _logger.Info("Enter FooBar Method"); } } public class CommonLog : ICommonLog { private readonly log4net.ILog _logger; public CommonLog(Type loggerType) { _logger = log4net.LogManager.GetLogger(loggerType); } public void Info(string message) { _logger.Info(message.Cleanse()); } // ... } I have tried this

Using StructureMap for dependency injection to SignalR 2.0.1

随声附和 提交于 2019-12-08 05:23:17
问题 I'm trying to use StructureMap for dependency injection to a SignalR hub. Many sources in the internet say this should be done as in this answer: How do you Resolve signalR v2.0 with StructureMap v2.6. I tried it, and got it to work - at least for the first action after the first pageload. When I try to leave the HTML page that includes the SignalR-JS-Code (or reload the page), or when I use one of the functions defined in my hub a second time, I get this StructureMapException: You cannot use

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

核能气质少年 提交于 2019-12-08 04:30:35
问题 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

Can't inject a delegate using ASP.NET Core DI

假装没事ソ 提交于 2019-12-08 04:30:35
问题 Say I've a MVC Core Controller like this: public class SomeController { public SomeController(IConfiguration appConfig, Func<string> someDelegate) { } } Also, I'm using AutoFac to resolve injections . Object injections are working flawlessly while adding a delegate injection produces an ASP.NET Core exception which tells that Func<string> can't be injected because there's no component to inject with such type. When I try to manually resolve SomeController using AutoFac I get the desired

In asp.net-mvc, is there a more elegant way using IOC to inject mutiple repositories into a controller?

爱⌒轻易说出口 提交于 2019-12-08 04:06:07
问题 I have an asp.net-mvc website and i am using ninject for IOC and nhibernate for my ORM mapping Here is my IOC binding code: internal class ServiceModule : NinjectModule { public override void Load() { Bind(typeof(IIntKeyedRepository<>)).To(typeof(Repository<>)).InRequestScope(); } } and here is an example of how I am doing IOC into my controller code: public FAQController(IIntKeyedRepository<FAQ> faqRepository, IUnitOfWork unitOfWork) { _faqRepository = faqRepository; _unitOfWork = unitOfWork

In ASP.NET Core, does the IoC ASP Startup Class solve what the Managed Extensibility Framework solved with a catalog and container?

六眼飞鱼酱① 提交于 2019-12-08 04:00:08
问题 I have read this, MEF (Managed Extensibility Framework) vs IoC/DI but it is dated. Since then MEF was added to Core. When I look at MEF and the IoC in ASP.NET Core, I cannot tell a lot of differences for a plugin architecture. Both "wire-up" dependencies. If I wanted to create a plugin in a Core application using IoC (the built in IoC), why not just change my ConfigureService methods? Is that the same as decorating imports and exports in MEF? How is composition different here, in 2017 (close

Typescript IOC in case of node

…衆ロ難τιáo~ 提交于 2019-12-08 03:35:03
问题 I am wondering how would you use typescript IOC specifically node app. In case of external module-based architecture there is no any classes in the app. Just pure modules because my app heavily depends on node_modules. How would I integrate IOC solution in such case? Any thoughts? Here is my specific case I want to use IOC for: I have mongoose model: interface IStuffModel extends IStuff, mongoose.Document { } var Stuff= mongoose.model<IStuffModel>('Stuff', Schemas.stuffSchema); export = Stuff