simple-injector

Simple Injector: RegisterInitializer does not always fire

佐手、 提交于 2019-12-12 22:22:47
问题 I use the RegisterInitializer method to inject properties in base types as follows: container.RegisterInitializer<BaseHandler>(handler => { handler.Context = container.GetInstance<HandlerContext>(); }); This works great, but the RegisterInitializer doesn't get fired on all registered types that inherit from BaseHandler. It doesn't seem to run when I call new myself: var url = ConfigurationManager.AppSettings["NotificationServiceUrl"]; container.Register<Handler<NotifyCustomerMessage>>(() =>

Can I write the results of SimpleInjectors diagnostics to a log file?

China☆狼群 提交于 2019-12-12 18:46:49
问题 Using SimpleInjector I call container.Verify() at the end of my configuration, and get the diagnostics information in the debugger as described in the documentation. I would like to write that information to a log file. Is there a way access it programmatically or a way hook a logger or tracer into SimpleInjector? 回答1: Simple Injector 2.4 contains a diagnostic API (SimpleInjector.Diagnostics.dll) that allow you to query the container for diagnostic warnings. Using this API you can write

How to unit test open generic decorator chains in SimpleInjector 2.6.1+

此生再无相见时 提交于 2019-12-12 15:28:16
问题 Given the following open generic deocrator chain using SimpleInjector: container.RegisterManyForOpenGeneric(typeof(IHandleQuery<,>), assemblies); container.RegisterDecorator( typeof(IHandleQuery<,>), typeof(ValidateQueryDecorator<,>) ); container.RegisterSingleDecorator( typeof(IHandleQuery<,>), typeof(QueryLifetimeScopeDecorator<,>) ); container.RegisterSingleDecorator( typeof(IHandleQuery<,>), typeof(QueryNotNullDecorator<,>) ); With SimpleInjector 2.4.0, I was able to unit test this to

Simple Injector fails to inject per Web API request registered class during Owin startup

て烟熏妆下的殇ゞ 提交于 2019-12-12 07:48:48
问题 I'm creating an API using Owin, Web API, Entity Framework, ASP.NET Identity. I'm using Simple Injector as my DI framework of choice. During the Owin startup process, I want to seed my database with some sample data. This is handled by a class implementing IDatabaseInitializer , which looks something like this: public class MyDbInitializer : DropCreateDatabaseAlways<MyDataContext> { private readonly IUserManager _userManager; public MyDbInitializer(IUserManager userManager) { _userManager =

Dynacache doesn't cache data

和自甴很熟 提交于 2019-12-12 05:15:42
问题 I am using Dynacache to cache data that will be eventually returned from a service call - to get things working I am just stubbing the data returned. I am using SimpleInjector for DI and got Dynacache registered with it as pointed out in the answer I got to a previous question So I have an integration project within my solution which contains the method I want to cache - which currently looks as below: [CacheableMethod(30)] public virtual List<MyResponse> GetDataByAccountNumber(int

SetResolver in console application using Simple Injector

你说的曾经没有我的故事 提交于 2019-12-12 00:23:36
问题 I am looking to do the equivalent of this: DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container)); But in a console application. I also have cases where I need to do this in a worker role. I don't want to have to add a reference to the MVC dll all over the place. I am wondering if there is an equivalent for non-mvc projects? I need to stash the container I create so I can access it throughout my application. I thought of creating a static variable, but I'd rather not

The constructor of type PaymentManager contains the parameter with name 'paymentMethods' and type List<IPaymentMethod> that is not registered

ε祈祈猫儿з 提交于 2019-12-11 17:12:22
问题 I am also getting the error below. Is this because its not a List, and if so how do I correct this? container.RegisterCollection<IPaymentMethod>(new[] { typeof(AuthorizeNetProvider), typeof(StripeProvider), typeof(PayPalProProvider), typeof(PayPalStandardProvider), typeof(IntuitProvider), typeof(UsaEpayProvider), typeof(ITransactProvider), typeof(SecureNetProvider), typeof(ExposurePayProvider), typeof(PayTraceProvider), typeof(BraintreeProvider) }); Error The configuration is invalid.

using simple injector with aspnet.identity

狂风中的少年 提交于 2019-12-11 15:39:12
问题 I'm trying to use simple injector with my mvc project, and I'm unclear how to complete all registrations for framework code. In particular, with this aspnet.identity code.In general, since this isn't my code and the call stack is through .net library .dlls, is there a way to get simpleinjector to work with this aspnet.identity code. Examples: In case below, I can see from subsequent code the the generic class that is instantiated from the generic interface, however I don't know how to

How do I make Simple Injector prefer implementations of the “most derived” interface?

懵懂的女人 提交于 2019-12-11 12:48:52
问题 In my data access layer I have a repository hierarchy that looks like this: <TEntity> IEntityRepository<---------+ICustomerRepository ^ ^ | | | | | | + | <TEntity> + EntityRepository<----------+CustomerRepository The IEntityRepository<TEntity> interface defines basic CRUD operations that will be useful regardless of entity type. EntityRepository<TEntity> is a concrete implementation of these operations. In addition, there are repository types for operations that are specific to a particular

Simple Injector Property Injection

早过忘川 提交于 2019-12-11 11:57:41
问题 How do you perform property injection with Simple Injector. The with Ninject you do is as per bellow: [Inject] public IUnitOfWork UnitOfWork { get; set; } How can I do the equivalent to this with Simple Injector. I tried finding a solution online but had no luck. Why do I want to use Property Injection? I want to use property injection to set up unit of work in my base controller so that it will create a new unit of work OnActionExecuting and commit the changes OnResultExecuted . It also