simple-injector

How to register Windows Forms with Simple Injector

放肆的年华 提交于 2019-11-27 05:22:09
Background I'm building a winforms application where I am using an IoC container (SimpleInjector) to register my types. In my application, a majority of the screens (i.e. forms) will only have one instance at any given time. Problem For forms that only need one instance at any given time, I can register them as singletons: container.Register<IHomeView, HomeView>(Lifestyle.Singleton); This allows me to use the container to keep track of all forms. In this case, however, when a form gets closed it will then get disposed (forms implement IDisposable). If the application tries to open that form

How to configure Simple Injector to run background threads in ASP.NET MVC

混江龙づ霸主 提交于 2019-11-27 01:46:33
问题 I am using Simple Injector to manage the lifetime of my injected dependencies (in this case UnitOfWork ), and I am very happy as having a separate decorator rather than my service or command handler looking after saving and disposing makes code a lot easier when writing business logic layers (I follow the architecture that is outlined in this blog post). The above is working perfectly (and very easily) by using the Simple Injector MVC NuGet package and the following code during the

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

▼魔方 西西 提交于 2019-11-27 01:03:30
问题 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:

Using DI container in unit tests

半世苍凉 提交于 2019-11-26 16:45:02
问题 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

Constructor injection with Quartz.NET and Simple Injector

丶灬走出姿态 提交于 2019-11-26 15:35:06
问题 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 } 回答1: According

Simple Injector Unable to Inject Dependencies in Web API Controllers

瘦欲@ 提交于 2019-11-26 14:35:23
I am attempting to do some basic constructor DI with Simple Injector, and it seems that it is unable to resolve the dependencies for Web API controllers. I have an API controller in an "API" folder, that is outside the "Controllers" folder. I have also tried placing it within the "Controllers" folder, but that did not seem to make much of a difference. The stack trace that I receive is similar to the one presented in this question . I am using a fresh install of the "Simple Injector MVC Integration Quick Start" NuGet Package (v. 2.1.0). I have the base SimpleInjectorWebApiDependencyResolver

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

心不动则不痛 提交于 2019-11-26 13:19:55
问题 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

Register IAuthenticationManager with Simple Injector

橙三吉。 提交于 2019-11-26 10:59:29
问题 I am having a configuration setup for Simple Injector where I have moved all of my registrations to OWIN pipeline. Now the problem is I have a controller AccountController which actually takes parameters as public AccountController( AngularAppUserManager userManager, AngularAppSignInManager signinManager, IAuthenticationManager authenticationManager) { this._userManager = userManager; this._signInManager = signinManager; this._authenticationManager = authenticationManager; } Now my Owin

Simple Injector Unable to Inject Dependencies in Web API Controllers

烈酒焚心 提交于 2019-11-26 03:57:09
问题 I am attempting to do some basic constructor DI with Simple Injector, and it seems that it is unable to resolve the dependencies for Web API controllers. I have an API controller in an \"API\" folder, that is outside the \"Controllers\" folder. I have also tried placing it within the \"Controllers\" folder, but that did not seem to make much of a difference. The stack trace that I receive is similar to the one presented in this question. I am using a fresh install of the \"Simple Injector MVC