simple-injector

Simple Injector and a Logging Abstraction Using Log4net

↘锁芯ラ 提交于 2019-12-08 08:17:06
问题 In order to try and get a nice logging abstraction with Log4net, I took the abstraction from this SO post and the adapter from this SO post and tried to get them working together. All that was really left to do was configure the container and that is the part which I have not succeeded in doing. The config which I have tried is public static class InfrastructureRegistry { public static void RegisterLoggingServices(this Container container) { container.RegisterConditional(typeof(ILog), c =>

Simple Injector FilterInjection seems to be reinitialising RegisterPerWebRequest injected item

邮差的信 提交于 2019-12-08 06:39:56
问题 I'm trying to move from Ninject to Simple Injector but I'm experiencing an odd issue when trying to duplicate functionality that worked with Ninject. In Ninject I had a service which contained: private readonly ICollection<Message> messages; This service was registered as Bind<INotificationService>().To<NotificationService>() .InRequestScope(); This service allowed messages (UI and error) to be passed back to the MVC site. This service was injected into an ActionFilterAttribute: kernel

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

Ninject WhenInjectedInto equivalent in Simple Injector

佐手、 提交于 2019-12-08 04:09:17
问题 Mapping to constant value. This happens for example when you need to resolve an automapper IMapper instance, Example in Ninject would be var config = new MapperConfiguration( cfg => { cfg.AddProfile( new MyMapperConfiguration() ); } ); Bind<MapperConfiguration>().ToConstant( config ).InSingletonScope(); Bind<IMapper>().ToConstant( config.CreateMapper() ); Bind different implementation based on the injecting type This happens when a set of common classes depends on a common interface but the

Multiple RegisterAll registrations using the same set of singletons with SimpleInjector

[亡魂溺海] 提交于 2019-12-08 02:15:30
问题 I'm building a plugin system for an e-commerce project with Simple Injector. I'm using RegisterAll to register all implementation of a IPaymentProvider and of a IResourceRegistrar (and in the fure more). But this creates a new instance each time. Here is it suggested to use RegisterSingle on each type. But how to achieve this in this case? private static void RegisterMultipleUnderOneInterface( Container container, string name) { IEnumerable<Type> pluginRegistrations = from dll in finder

Setup Simple Injector with ASP.NET Identity 2.2.1

只愿长相守 提交于 2019-12-07 12:55:10
问题 So I've been trying to setup ASP.NET Identity 2.2.1 and I keep hitting roadblocks. For being something that is supposed to be auto-generated by the framework it sure seems complicated to configure. I think I'm almost there but I'm still having issues setting up IoC with Simple Injector. I've been reading through other StackOverflow questions and blogs about these issues. Most of them seem out of date because they deal with ASP.NET Identity 1.0. There's even been enough changes from 2.0 to 2.2

AOP implemented with the Decorator pattern over a Generic Repository

拈花ヽ惹草 提交于 2019-12-07 08:10:26
问题 I'm trying to build a prototype that applies Aspect Oriented Programming to my project using Decorators. Some portion of my project will use a generic Repository (for simple CRUD), but eventually I'll also incorporate Command and Query handlers (these will perform specific tasks like ProcessCustomerOrders, etc.). Also, the cross-cutting concerns I’d like to example here are Security and Logging. Also, I know that my example code is not the using the Decorator pattern, but is just an example

How to change dependency registration at run time using simple injector?

风流意气都作罢 提交于 2019-12-07 07:57:13
问题 I'm using the Simple Injector IoC framework, and I would like to be able to change the dependency registration at run time. For example, I have two implementations, A and B , of interface I . Implementation A is registered at app start, but depending on some flag which can change during runtime, I would like to switch the implementation. We are currently doing this the OnActionExecuting event of our BaseController , which all of our controllers inherit from. Here is the sample code of what I

How to do a registration in Simple Injector after a GetInstance call / Alternate solution?

99封情书 提交于 2019-12-07 03:29:07
问题 Consider the following example: public class CommunicationClient : IClient { public CommunicationClient(IServerSettings settings) { ... } // Code } public class SettingsManager : ISettingsManager { SettingsManager(IDbSettingManager manager) // Code public IDictionary<string, string> GetSettings() { ... } } Problem : While performing registrations (using SimpleInjector ), I need to provide values that are obtained from an instance of SetingsManager and fill ServerSettings instance (concrete

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