simple-injector

Register multiple implementations with single interface

爷,独闯天下 提交于 2019-12-06 19:33:25
问题 Is there a way to register a single interface which is implemented by more than one concrete class using [simple-injector] and without using template interface? say we have 2 classes MyClass1 and Myclass2 and both these classes are implementing IInterface1 Now using [simple-injector] we were not able to do this container.Register<IInterface1, Myclass1>(); container.Register<IInterface1, Myclass2>(); converting existing interface to template interface is kinda a hard job on the existing

DbContext Lifestyle per Screen/ViewModel (WPF + Simple Injector)

时光毁灭记忆、已成空白 提交于 2019-12-06 14:40:52
问题 I have an WPF application that adheres command/query pattern and uses EF as an ORM. In my mind, when new ViewModel is created, new instance of DbContext should be created and that same instance should be reused across (injected into) all command/query handlers, which are created within the scope of that particular ViewModel. At the end of ViewModel's lifetime, DbContext should be disposed. How to achieve such a setup with Simple Injector? 回答1: If you are applying the command/handler and query

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

我们两清 提交于 2019-12-06 14:36:07
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 code with null checks. Are there any nicer ways or different architectures to achieve this linking of

Simple Injector: Different DbContext for selected controllers

自古美人都是妖i 提交于 2019-12-06 12:45:31
I am trying to separate reads/writes in my MVC application. I am using Simple Injector as Ioc and I have following structure: new Service( new Repository( new UnitOfWork( new DbContext()))) So UnitOfWork registered per web request all the rest Transient . So idea was to create separate read-only controllers and make a registration of DbContext to supply a different connection if controller is read-only. And that could be achievable with improved RegisterWithContext extension BUT it will not work in my case because not all graph nodes are Transient . Is there any way (more elegant than register

Membership reboot replace Ninject with Simple Injector

泪湿孤枕 提交于 2019-12-06 06:16:02
问题 I need add membership reboot (RavenDb) into the project that use IOC Simple Injector Ninject implementation var config = MembershipRebootConfig.Create(); kernel.Bind<MembershipRebootConfiguration<HierarchicalUserAccount>>().ToConstant(config); kernel.Bind<UserAccountService<HierarchicalUserAccount>>().ToSelf(); kernel.Bind<AuthenticationService<HierarchicalUserAccount().To<SamAuthenticationService<HierarchicalUserAccount>>(); kernel.Bind<IUserAccountRepository<HierarchicalUserAccount>>()

Multiple RegisterAll registrations using the same set of singletons with SimpleInjector

一个人想着一个人 提交于 2019-12-06 06:07:25
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.Assemblies from type in dll.GetExportedTypes() where type.GetInterfaces().Any(i => i.Name == name) where

UserManager dependency injection with Owin and Simple Injector

↘锁芯ラ 提交于 2019-12-06 05:42:12
After adding Simple Injector to my project to create an instance of my UserAppManager that will exist through the whole lifetime of a session I started to recieve errors: Error with no parameterless constructor: An error occurred when trying to create a controller of type 'AuthController'. Make sure that the controller has a parameterless public constructor. Error with a parameterless constructor: For the container to be able to create AuthController it should have only one public constructor: it has 2. I followed a guide ( https://simpleinjector.codeplex.com/discussions/564822 ) to avoid

MassTransit and Simple Injector [closed]

你说的曾经没有我的故事 提交于 2019-12-06 05:30:01
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I'm reviewing the MassTransit Distributed Application Framework for .NET. According to the website MassTransit has been built from the beginning with the concept of an IoC container being involved and provides

Setup Simple Injector with ASP.NET Identity 2.2.1

混江龙づ霸主 提交于 2019-12-06 02:00:33
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.1 I've run into some issues with out of date solutions. Or the solutions deal with other IoC

How to check whether DbContext has transaction?

青春壹個敷衍的年華 提交于 2019-12-05 19:04:46
问题 Background: I have WCF service with SimpleInjector as IoC which creates instance of DbContext per WCF request. Backend itself is CQRS. CommandHandlers have a lot of decorators (validation, authorization, logging, some common rules for different handler groups etc) and one of them is Transaction Decorator: public class TransactionCommandHandlerDecorator<TCommand> : ICommandHandler<TCommand> where TCommand : ICommand { private readonly ICommandHandler<TCommand> _handler; private readonly