Questions tagged [simple-injector]

1

votes
1

answer
65

Views

ASP.NET Core DI with Simple Injector sharing DbContext

I'm setting up an ASP.NET Core project and following a CQRS pattern basing my work on the Tripod project. I've followed the Simple Injector integration guide but a little puzzled on one point... I want to keep make use of the UseInMemoryDatabase option for testing and can only find examples of that...
Stephen York
1

votes
2

answer
113

Views

How to inject application service into AuthenticationHandler

I have a custom AuthenticationHandler implementation that depends on application service. Is there a way to resolve dependencies of AuthenticationHandler from Simple Injector? Or maybe cross-wire registration so that applications services can be resolved from IServiceCollection? Sample implementatio...
Andrii Litvinov
1

votes
0

answer
251

Views

Using Simple Injector with EF in WPF app

In my wpf app I need to be able to read/write data from specific table/tables, so, as I'm using SimpleInjector to use all services and stuff. So, basically I want to be able to use repository in some of my services. First I found this How to use Simple injector, Repository and Context - code first A...
DanilGholtsman
1

votes
1

answer
253

Views

How to inject database connection to query handler?

I have an app which is similar to this app. Inside query handlers I use Dapper for getting data. DI container is SimpleInjector. How should I inject a database connection in query handlers? Is it good to register IDbConnection in the DI container? What if I have several DB connections? How should I...
Katomi
1

votes
1

answer
329

Views

Controller is registered as transient, but implements IDisposable

var container = new Container(); container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle(); container.RegisterInstance(new SqlConnection(connectionString)); container.Register(Lifestyle.Scoped); container.Register(Lifestyle.Scoped); container.Register(Lifestyle.Scoped); container.Registe...
Кириллка
1

votes
1

answer
98

Views

Inject two specific interface implementations into constructor with Simple Injector

I have and interface IConnector. And have some implementations, say SomeConnector. And my use case looks like: public class Worker : IWorker { public Worker(IConnector dataConnector, IConnector transactionConnector) {} } public class SomeConnector : IConnector { public SomeConnector(IConnectorContex...
shda
1

votes
0

answer
336

Views

Audit.EntityFramework with Simple Injector On .Net Core

I'm currently using .net core 2.0 along with Audit.EntityFramework to audit changes on my entities. I've gone the route of creating my own CustomProvider as explained here DataProviders brief excerpt below. EmployerCustomDataProvider public class EmployerCustomDataProvider : AuditDataProvider, IEmpl...
Darren
1

votes
1

answer
283

Views

Simple Injector with ASP.NET Core With Full .NET Framework (.NET 4.7)

I am using ASP.NET Core with the full .NET framework and want to try Simple Injector. In the Nuget manager, I see so many options for Simple Injetcor e.g. 'SimpleInjector.Integration.AspNetCore.MVC' and 'SimpleInjector.Integration.AspNetCore.Mvc.Core' I don't see any diff in release or dependencies....
user7784348
9

votes
2

answer
6.2k

Views

Using DI container in unit tests

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 de...
Jeff Dege
1

votes
0

answer
69

Views

JWT & Simple Injector. Set connectionstring OnTokenValidated

I am new to this kind of concepts so i am kinda stuck on this (explanation of what i aim for a little bellow). I have the following code in a rest web api: UnitOfWorkProvider.cs public class UnitOfWorkProvider : IUnitOfWorkProvider { private readonly Func getDbContext; public UnitOfWorkProvider(Func...
John
1

votes
1

answer
86

Views

Integrate Simple Injector with optional ASP.NET Core Web API

I followed this guide https://simpleinjector.org/aspnetcore for getting a basic app up and running. And it works great. My needs now are a bit different, however. The Web API in my app is basically an optional endpoint that may not be started. I want to use the Simple Injector for DI across the enti...
UmaN
1

votes
0

answer
67

Views

SimpleInjector injects an empty collection when using a generic interface

I'm trying to implement a similar scenario of CompositeValidator in the Simple Injector docs. Here is the composite class: public class CompositePriceCalculator : IPriceCalculator { private readonly IEnumerable _priceCalculators; public CompositePriceCalculator(IEnumerable priceCalculators) { this....
ohadinho
1

votes
1

answer
92

Views

How to Properly configure Simple Injector with Async Tasks

I have self-hosted WebAPI inside my ASP.NET MVC application. I want to perform some asynchronous action when one of my API action is executed. The asynchronous action has dependency on DbContext along with some other dependencies. Following is my Simple Injector configuration. public class SimpleIn...
Nitesh Saxena
1

votes
1

answer
41

Views

How to use Simple Injector with svc-less service implementations

I'm considering switching from Autofac to Simple Injector due to seemingly better decorator support. But I'm very fond of the way you register and host svc-less WCF services with Autofac and I can't find a way to do exactly that with Simpleinjector. For instance, with Autofac it works like this (in...
Jacob S.
1

votes
0

answer
50

Views

Simple Injector - Transient object implementing IDisposable, depending on other transient objects

I am writing a service that tells multiple classes implementing the interface IDeviceFinder to go look for connected devices, which the service will put in a cache for other objects to use. The controller script looks as follows: private Container _container; public bool Start() { _container.Collect...
L. Kneringer
1

votes
0

answer
28

Views

Property Injection for User Controls in WinForms

I have inherited an a VB.NET WinForms application. It is very poorly written with a lot of bad practices. The first order of business is to get some DI into the app with a container to resolve the dependencies so I can start breaking this thing up and getting it under test. This is my first WinForms...
JDBennett
1

votes
1

answer
1.1k

Views

Simple Injector: RegisterInitializer does not always fire

I use the RegisterInitializer method to inject properties in base types as follows: container.RegisterInitializer(handler => { handler.Context = container.GetInstance(); }); This works great, but the RegisterInitializer doesn't get fired on all registered types that inherit from BaseHandler. It does...
Smitha
1

votes
1

answer
477

Views

Simple Injector set property whilst object graph is built

Using Simple Injector I have come across a common theme with my logger where I set the logger name in the constructor of the service object to which the logger is injected. When the service writes to the log, it can be easily identified by this logname. Since LogNames will be set for each service, t...
g18c
1

votes
1

answer
188

Views

Structure to handle database connection errors with SimpleInjector

I have an Entity Framework application connecting to an SQL server on a separate box. The program flow can be broken down in to two states: Init the composition root and register types using the Simple Injector DI framework Init application (does some reads and writes with the SQL database using Ent...
g18c
1

votes
1

answer
892

Views

SimpleInjector and System.Web.Mvc.Async threads

I asked before a question here, and I read this question/answers about multi-threading and I know those solutions. But today I get a new problem. When we are using commands (or where we can access the original code to manage and modify it) the async-decorator that suggested in above answers works. B...
javad amiry
1

votes
1

answer
589

Views

Simple Injector async life time scoping and security exception

I have a AsyncCommandHandlerDecorator and LifetimeScopedCommandHandlerDecorator as shown below: public class AsyncCommandHandlerDecorator : ICommandHandler where TCommand : ICommand { private readonly Func _factory; public AsyncCommandHandlerDecorator(Func factory) { _factory = factory; } [Security...
javad amiry
1

votes
1

answer
117

Views

Decorating interfaces of different lifestyles

I use Simple Injector as my IoC container. SimpleInjector uses this simple technique to handle mixed life style for Per Thread and Per Web Request container.RegisterPerWebRequest(); container.RegisterLifetimeScope(); container.Register(() => container.GetInstance()); // Register as hybrid PerWebRequ...
qujck
1

votes
1

answer
671

Views

SimpleInjector resolving all types implementing an interface without explicitly binding

I have an interface 'ISetting'. I have POCO classes the implement this empty interface with some properties with some auto getter/setters. I would like for SimpleInjector to inspect every type requested (that isn't explicitly registered), and if it implements this interface, resolve it with a method...
Paul Knopf
1

votes
1

answer
173

Views

Does SimpleInjector have the ability to assign a priority order when using RegisterManyForOpenGeneric/GetAllInstances

I am using SimpleInjector as my IoC Container. I have created a Publish/Subscribe framework for which I now need to be able to refine by enabling subscribers to indicate their priority for execution. For example I could create a subscriber for preloading all of the data required for the remainder of...
qujck
1

votes
1

answer
429

Views

When would you need SimpleInjector hybrid registration? (How can an object hosted in IIS be called without a HttpContext?)

Following on from my recent question regarding SimpleInjector and hybrid web request/thread lifestyles it seems I do not fully understand the technical requirements and have been doing something I don't actually need to do. With this code interface IUnitOfWork { } interface IWebUnitOfWork : IUnitOfW...
qujck
1

votes
1

answer
626

Views

Migration Ninject -> Simple Injector

We use Ninject in our project, but have some performance problems. It will be interesting to test the same project with Simple Injector. Do you know some kind of guides that make the migration easier?
MikroDel
1

votes
1

answer
740

Views

Replace Ninject code with Simple Injector

I have found this post Replace Ninject with Simple Injector but havent found the solution for following migrations. With Ninject: public class ServiceClass : IServiceClass ... IKernel kernel ... this.kernel.Bind().ToMethod(context => this); I try to use this construction with Simple Injector: public...
MikroDel
1

votes
1

answer
907

Views

How to correctly use SimpleInjector - RegisterAllOpenGeneric

I'm unable to figure out the correct way to use RegisterAllOpenGeneric I have these simple definitions: public interface ISubscribeTo { } public class AnEventOf { } public interface IMarker { } public class PocoB : IMarker { } and a normal Subscriber: public class SubscribeToPocoB : ISubscribeTo { }...
qujck
1

votes
1

answer
821

Views

Binding an open generic type to a method in Simple Injector

I'm trying to configure the SharpRepository project to also make use of SimpleInjector IOC framework as an IOC optioni in the framework but am stuck on porting some of the code. Can't figure out how to pass in generic interfaces using SimpleInjector. 2nd issue/question is how to get the generic a...
bbqchickenrobot
1

votes
2

answer
1.6k

Views

Bounded Context and Generic Repository with Entity Framework and wiring with Simple injector IoC

Been reading a lot on StackOverflow and couldn't find any question/answer exact similar to this one. Try to keep it short. My key problem is how to design a Generic Repository when you have several bounded contexts. I have been using Generic repository before a lot but then I usually close them thr...
Magnus Backeus
1

votes
1

answer
293

Views

Simple Injector: Automatic constructor injection recursion

I am trying to understand how automatic constructor injection is done in SimpleInjector.NET. My working source code is from the Code Project article (v1.5.0.12199). I have looked at the Container's GetInstance)() code and also the InstanceProducer's GetInstance() code but I don't see any recursive c...
Tim Robbins
1

votes
1

answer
356

Views

How to use composite handler with nested open generic?

public interface IMessage { } public interface ICommand : IMessage { } public interface IEvent : IMessage { } public interface IMessageHandler { void Handle(T message); } public class ItemCreatedEvent : IEvent { public string Name { get; set; } } public class ValidateMessageEnvelope { public TMessag...
oguzh4n
1

votes
1

answer
1.2k

Views

Simple Injector exception: cannot load dlls when web api project starts

I got this exception 'Could not load file or assembly System.Web.Http, Version=4.0.0.0' when starting my WebApi application, I register in the AppStart method. protected void Application_Start() { RegisterInjector(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFi...
Bargitta
1

votes
1

answer
210

Views

SimpleInjector Request Scope from Service layer

I have a multi-tier application where my implementation of my DbContext and UnitOfWork is lying in my service layer. This layer does not have a reference to System.Web. Together with the implementations lies my CompositionRoot class which is referred from my UI layer, using extensions, to initialize...
janhartmann
1

votes
1

answer
354

Views

Resolve handlers using Factory via IOC container

I have the task of refactoring a monolithic MVC application (1 controller action with over 1000 lines) into something more manageable. The purpose of the program is to parse collections of different types, one by one, in a specific order. Here is an example of a proposed 'better' solution... public...
Baldy
1

votes
1

answer
134

Views

Simple Injector Fallback Registration

I read in the documentation that it's possible to create fallback registrations for unhandled types but I can't seem to find that page any longer. In any case, my question is quite simple assuming I understand fallback registration. I would like to setup the container to instantiate a NullCommandHa...
bbqchickenrobot
1

votes
1

answer
958

Views

Reflect changes made by stored procedure in EF context

I am using SimpletInjector to inject the entity framework context in controller using following code: private static void Initializer(Container container) { container.RegisterSingle(); container.RegisterSingle(); } I am using the injected context to execute stored procedure which will have only UPDA...
Manikandhar
1

votes
1

answer
130

Views

Checking if IoC registrations implement command or query interfaces, and returning the generic parameter

I am using the SimpleInjector IoC container and trying to wire-up functionality on application start-up (the container will report what command-handlers and query-handlers it has registered, and we will register the commands and queries that were registered as generic types): var suppportedCommands...
g18c
1

votes
1

answer
103

Views

ASP.NET WebForms and SimpleInjector FindControl throws no parameterless constructor

I have Web Application in Asp.NET (4.5) and Simple Injector. All application works right and Simple Injector too. But the problem is with FormView: fffff And in cs I try to get this label: protected void Page_Load(object sender, EventArgs e) { Control testDDL = MyFv.FindControl('myLblTest'); but tes...
Robert
1

votes
2

answer
89

Views

Odd “Creating the instance for IConfiguration failed” Configuration Error

I'm setting up a SimpleInjector container, and I have one class that has a hierarchy like: TestConfiguration (class I'm working with) BaseConfiguration (abstract class) IConfiguration (interface used for registering) There are a lot of IConfiguration objects listed and I'm using a dynamic process fo...
Brian Mains

View additional questions