simple-injector

How to change registered (Simple Injector) DbContext's connection string after user's authorization?

巧了我就是萌 提交于 2020-08-09 08:13:54
问题 I'm building ASP.NET Core Web Api with Simple Injector and have the following problem: The data for each user is stored in his individual base (but with the same schema), which is known only after he authorizes himself. So... I can give DbContext it's proper connection string only after user's authorization. What is the best way to accomplish this? For now I am storing the connection string in HttpContext custom claim and am refering to it with a use of a static helper class in DbContext 's

Creating custom Simple Injector Scope in Web Forms

会有一股神秘感。 提交于 2020-06-28 06:15:40
问题 I have a text box and a button in my Windows forms application. When the start key is pressed with the value written in the textbox, a new Form should be opened with this value. I want to create a scope for each opened form. And when I close the form I want to close the relevant scope. How do I create a custom scope with the simple injector? Here is a simple sample code static class Program { static readonly Container container; static Program() { container = new Container(); container

Dependency injection with IAuthorizationFilter in SimpleInjector

江枫思渺然 提交于 2020-06-28 06:04:16
问题 I have a class PermissionFilter that implements IAuthorizationFilter from System.Web.Mvc . Since it has dependencies that are already mapped, I want to use SimpleInjector to provide it. I'm doing this (which was working with Ninject): public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(DependencyResolver.Current.GetService(typeof(PermissionFilter))); } But I get the error: Value cannot be null. Parameter name: instance I tried to get an instance of the

How to perform async initalization of lazy injection

冷暖自知 提交于 2020-06-25 10:31:17
问题 Let's say we want to inject an object that is expensive to create (let's say it does initialization from a database), so we would typically use some kind of factory or Lazy<T> . However, if we're injecting this object into an MVC or WebApi controller that is using async action methods, we don't want to block these methods on the expensive I/O operation when the Lazy object is initialized, which defeats the purpose of using async. Certainly, I could create an "initlize" method that is async,

Get specific interface for a single specified concrete type, with decorators applied with Simple Injector

烈酒焚心 提交于 2020-05-28 05:48:09
问题 I am using SimpleInjector with MediatR and hooking up my INotifications and INotificationHandlers<INotification> with attributes on my implementation classes - this is so we can map message bus messages (aka notifications) to notification handlers: Host app receives message from bus Message is parsed into Notification POCO Container is used to look up notification handler(s) Notification is dispatched to each handler Traditionally one would register all INotificationHandler<> with Container

Get specific interface for a single specified concrete type, with decorators applied with Simple Injector

為{幸葍}努か 提交于 2020-05-28 05:46:29
问题 I am using SimpleInjector with MediatR and hooking up my INotifications and INotificationHandlers<INotification> with attributes on my implementation classes - this is so we can map message bus messages (aka notifications) to notification handlers: Host app receives message from bus Message is parsed into Notification POCO Container is used to look up notification handler(s) Notification is dispatched to each handler Traditionally one would register all INotificationHandler<> with Container

Get specific interface for a single specified concrete type, with decorators applied with Simple Injector

有些话、适合烂在心里 提交于 2020-05-28 05:46:06
问题 I am using SimpleInjector with MediatR and hooking up my INotifications and INotificationHandlers<INotification> with attributes on my implementation classes - this is so we can map message bus messages (aka notifications) to notification handlers: Host app receives message from bus Message is parsed into Notification POCO Container is used to look up notification handler(s) Notification is dispatched to each handler Traditionally one would register all INotificationHandler<> with Container

Get specific interface for a single specified concrete type, with decorators applied with Simple Injector

谁都会走 提交于 2020-05-28 05:46:06
问题 I am using SimpleInjector with MediatR and hooking up my INotifications and INotificationHandlers<INotification> with attributes on my implementation classes - this is so we can map message bus messages (aka notifications) to notification handlers: Host app receives message from bus Message is parsed into Notification POCO Container is used to look up notification handler(s) Notification is dispatched to each handler Traditionally one would register all INotificationHandler<> with Container

Simple Injector dynamic context-based injection at runtime between two registrations

巧了我就是萌 提交于 2020-05-17 06:02:08
问题 I have a Mediator application using Simple Injector for command handler registration, and injection and handlers is all setup and working perfectly. class DoWashingCommandHandler : IRequestHandler<DoWashingCommand,object> { IBus bus; public DoWashingCommandHandler(IBus bus) { this.bus = bus; } Task<object> Handle(DoWashingCommand command) { this.bus.Send(new OtheCommand()); } } I have a need for 2 registrations of a IBus implementations. The first can be of any lifetime, the second has a

The container can't be changed after the first call to GetInstance, GetAllInstances, Verify, and some calls of GetRegistration

放肆的年华 提交于 2020-05-15 21:31:05
问题 I cant figure out why I am getting this error below within the RegisterCollection method. Am I doing the setup incorrectly? The container can't be changed after the first call to GetInstance, GetAllInstances, Verify, and some calls of GetRegistration. Please see https://simpleinjector.org/locked to understand why the container is locked. The following stack trace describes the location where the container was locked: Logger registration public static void Register(Container container) {