simple-injector

Pass runtime value to constructor using Simple Injector abd WebFormsMVP

偶尔善良 提交于 2019-11-28 12:23:46
I'm trying to combine SimpleInjector with WebFormsMvp . To facilitate DI WebFormsMvp provides the IPresenterFactory interface. It contains the Create method which provides the presenter type to resolve and the view instance . I need to inject the view instance into the constructor of the presenter . The presenter also has other dependencies that need creating by the container . This is what I got so far, but it is not ideal. What's the correct solution for the problem? Presenter constructor: public FooPresenter(IFooView view, IClientFactory clientFactory) : base(view) Factory: public class

How to do open generic decorator chaining with unity + UnityAutoRegistration

我们两清 提交于 2019-11-28 10:34:52
Went off on an interesting tangent today after reading this article on command handler decoration . I wanted to see if I could implement the pattern using Unity instead of SimpleInjector , and so far it is proving extremely difficult. The first thing I had to do was install UnityAutoRegistration to resolve the open generic ICommandHandler<TCommand> interface. Current solution for that aspect is as follows: Container = new UnityContainer().LoadConfiguration(); Container.ConfigureAutoRegistration() .ExcludeSystemAssemblies() .Include(type => type.ImplementsOpenGeneric(typeof(ICommandHandler<>)),

Mixed lifestyle for Per Thread and Per Web Request with Simple Injector

泪湿孤枕 提交于 2019-11-28 05:31:24
I'm using SimpleInjector as my IoC library. I register DbContext as per web request and it works fine. But there is one task that I run it in a background thread. So, I have a problem to create DbContext instances. e.g. Service1 has an instance of DbContext Service2 has an instance of DbContext Service1 and Service2 run from background thread. Service1 fetches an entity and pass it to Service2 Service2 uses that entity, but entity is detached from DbContext Actually the problem is here: Service1.DbContext is difference from Service2.DbContext . It seems when I run a task in a separate thread

How to register AutoMapper 4.2.0 with Simple Injector

China☆狼群 提交于 2019-11-28 03:18:51
问题 Updated to AutoMapper 4.2.0, and following the migration guide available here: https://github.com/AutoMapper/AutoMapper/wiki/Migrating-from-static-API/f4784dac61b91a0df130e252c91a0efd76ff51de#preserving-static-feel. Trying to translate code on that page for StructureMap to Simple Injector. Can someone show me what this code looks like in Simple Injector? StructureMap public class AutoMapperRegistry : Registry { public AutoMapperRegistry() { var profiles = from t in typeof (AutoMapperRegistry)

Using Simple Injector with SignalR

被刻印的时光 ゝ 提交于 2019-11-27 17:32:12
I thought using my own IoC would be pretty straight forward with SignalR and maybe it is; most likely I'm doing something wrong. Here's my code I have so far: private static void InitializeContainer(Container container) { container.Register<IMongoHelper<UserDocument>, MongoHelper<UserDocument>>(); // ... registrations like about and then: var resolver = new SimpleInjectorResolver(container); GlobalHost.DependencyResolver = resolver; } and then my class: public class SimpleInjectorResolver : DefaultDependencyResolver { private Container _container; public SimpleInjectorResolver(Container

Using Simple Injector in Web API and OWIN

心不动则不痛 提交于 2019-11-27 16:09:34
问题 I'm experiencing the same problem as described here and my set up is almost identical to this that is actually based on this guide. When I access a method in my controller I get this An error occurred when trying to create a controller of type 'TestController'. Make sure that the controller has a parameterless public constructor. Here's the stack trace at System.Web.Http.Dispatcher.DefaultHttpControllerActivator .Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor

Using DI container in unit tests

孤街浪徒 提交于 2019-11-27 14:28:17
We've been using Simple Injector with good success, in a fairly substantial application. We've been using constructor injection for all of our production classes, and configuring Simple Injector to populate everything, and everything's peachy. We've not, though, used Simple Injector to manage the dependency trees for our unit tests. Instead, we've been new'ing up everything manually. I just spent a couple of days working through a major refactoring, and nearly all of my time was in fixing these manually-constructed dependency trees in our unit tests. This has me wondering - does anyone have

Constructor injection with Quartz.NET and Simple Injector

元气小坏坏 提交于 2019-11-27 11:34:17
Currently I am writing a service using Quartz.NET to schedule the running of it. I was wondering if anyone has any experience of using constructor injection with Quartz.NET and Simple Injector. Below is essentially what I wish to achieve public class JobImplementation: IJob { private readonly IInjectedClass injectedClass; public JobImplementation(IInjectedClass _injectedClass) { injectedClass = _injectedClass } public void Execute(IJobExecutionContext _context) { //Job code } According to this blog post , you would need to implement a custom IJobFactory , like this: public class

Avoiding all DI antipatterns for types requiring asynchronous initialization

十年热恋 提交于 2019-11-27 11:10:16
问题 I have a type Connections that requires asynchronous initialization. An instance of this type is consumed by several other types (e.g., Storage ), each of which also require asynchronous initialization (static, not per-instance, and these initializations also depend on Connections ). Finally, my logic types (e.g., Logic ) consumes these storage instances. Currently using Simple Injector. I've tried several different solutions, but there's always an antipattern present. Explicit Initialization

Using Simple Injector with Unit Of Work & Repository Pattern in Windows Form

和自甴很熟 提交于 2019-11-27 07:30:51
I'm trying to implement IoC in my windows form application. My choice fell on Simple Injector, because it's fast and lightweight. I also implement unit of work and repository pattern in my apps. Here is the structure: DbContext : public class MemberContext : DbContext { public MemberContext() : base("Name=MemberContext") { } public DbSet<Member> Members { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();\ } } Model : public class Member { public int MemberID {