Questions tagged [simple-injector]

Simple Injector is an Dependency Injection library for Microsoft .NET, .NET Core, .NET Standard, Windows Phone, Windows Store Apps, and Mono.

Filter by
Sorted by
Tagged with
1 vote
2 answers
44 views

Resolving and initializing view models created at runtime with a DI container

Our application is similar to an IDE. The user can open files (coming from a DB), and then use the application's various aspects to edit that file. The application can have multiple tabs with ...
  • 9,420
0 votes
1 answer
55 views

SimpleInjector - Registering plugins dynamically with constructor values from config

According to the documentation of SimpleInjector one can use the following code to load assemblies dynamically string pluginDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "...
  • 25
0 votes
1 answer
27 views

SimpleInjector Creates Controller Multiple Times and Creates Unnecessary Controller

I noticed a strange behavior when using SimpleInjector with ASP.NET Web APIs, so I reduced it to its basics. Steps to reproduce: create ASP.NET Core's default Web API project. I used .NET Core 3.1, ...
  • 169
0 votes
1 answer
27 views

SimpleInjector Container.Verify() with HTTP context-scoped dependency

I have the following basic SI registration in an ASP.NET WebApi project. Startup.cs public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services....
  • 169
0 votes
1 answer
61 views

Intercept all instances using Simple Injector

I want to do some integration testing using Simple Injector. However, sometimes I need to check whether a specific internal service has been called with the correct arguments. I am already using ...
  • 2,961
0 votes
2 answers
49 views

WPF SimpleInjector call to client.GetAsync hanging

I am trying to use SimpleInjector in a WPF Application (.NET Framework). We use it in exactly the same way in many of our Services but for some reason when I am attempting to implement the same logic ...
0 votes
1 answer
65 views

SimpleInjector DI container nested scopes

There is a Console Application. There are 3 services: public class SingletonService { public SingletonService() { Console.WriteLine("SingletonService constructor"); } } ...
0 votes
1 answer
90 views

Snyk finds vulnaribilities in Simple Injector

In our .NET 6 apis we are using Simple Injector for dependency injection. With the latest version of Simple Injector, we observed that Snyk found five high-priority vulnerabilities and two medium ...
2 votes
2 answers
113 views

Elmah logger not working in Web API with Simple Injector

In an ASP.NET Web API project, if you are using Simple Injector for dependency injection, it will register all controllers with this line of code: container.RegisterWebApiControllers( System.Web....
  • 24.9k
0 votes
1 answer
84 views

Supplying runtime data to the Container inside a parallel for loop

public class Factor1(int FactorX, int FactorY) : IFactors; public class Factor2(int FactorX, int FactorY, int FZ) : IFactors; public interface IFactors { int FactorX { get; set; } int FactorY ...
1 vote
1 answer
79 views

Some services are not able to be constructed in a AuthorizationHandler

Consider the following services.AddSingleton<IActionContextAccessor, ActionContextAccessor>(); services.AddSingleton<IAuthorizationHandler, AccountHandler>(); ... services.AddSingleton<...
  • 21.9k
2 votes
1 answer
46 views

SimpleInjector CrossWiring confusion

I've been looking through the Simple Injector documentation and thought I was doing things right regarding Crosswiring, but alas... I have the following which fails to resolve my App through the ...
  • 1,178
0 votes
1 answer
154 views

C# : How to access variables from event handler with DI container like Simple Injector?

I am working on a .NET core MVC web app. I have a domain object method that perform some business logic and return a result object containing variables passed to view models. The result object has ...
  • 189
0 votes
1 answer
248 views

Implement mapster dependency injection via Simple Injector IoC container

I'm using Mapster for mapping and Simple Injector in my .net framework 4.8 MVC and WebApi controllers. I'd like to inject Mapster as a dependency in my services but I can't figure it out how to make ...
  • 31
0 votes
0 answers
75 views

Setting scoped lifetime of web request in SimpleInjector ASP.NET Core 5 gives InvalidOperationException

having a fresh setup of asp.net core 5 app gives me the problem of not beeing able to set a per web request scope as SimpleInjector tells me to setup a scoped default lifestyle which is in an old ...
  • 407
0 votes
0 answers
110 views

ASP.NET MVC 5 : no IUserTokenProvider is registered when sending forgot password email

I'm trying to send a reset password email, but I keep receiving the error No IUserTokenProvider is registered on the line string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); I ...
  • 1,983
0 votes
1 answer
137 views

IHttpClientFactory and SimpleInjector in AzureFunctions

In Azure Functions (v3 on NetCore3.1) using SimpleInjector 5.3, I've followed the guidance here using IHttpClientFactory instead of a typed client that depends on a MS DI-constructed HttpClient, but ...
  • 1,535
0 votes
0 answers
42 views

Calling the PredicateContext.Consumer property for a conditional registration that is requested directly from the container is not supported

I am trying to register conditionally (based on implementation type) a custom ApiClient using SimpleInjector as can be seen in the following function. private static void RegisterEndpoint<...
  • 15.1k
0 votes
0 answers
38 views

how to get IOC container?

Hello i am working with an asp.net webapi program. i am trying to use simple injector. i can init and register types in application start . but I have a question: how to get container instance to ...
  • 83
1 vote
1 answer
147 views

Conditionally register collection in Simple Injector

I would like to conditionally register types to a collection based on who the Consumer is. Something like: Container.Collection.RegisterConditionally( typeof(IEventHandler<>), ...
  • 317
0 votes
1 answer
710 views

Multiple Hosted Service With Simple Injector

i'm trying to follow this example here the only thing is i need to inject multiple hosted services instead of one like this services.AddSimpleInjector(container, options => { // Registers the ...
0 votes
0 answers
111 views

IClassFixture called multipletimes with locked Simple Injector Container

i'm trying to test my controllers with IClassFixture<WebApplicationFactory<Startup>>, but when i run multiples tests i get the error: System.InvalidOperationException : The container can'...
  • 36
1 vote
1 answer
229 views

Equivalent Simple Injector .Register invocations

I have an object whose constructor requires a primitive. I register it using a delegate (please excuse the contrived example). container.Register<Account>(() => new Account(1000M), Lifestyle....
  • 66
1 vote
1 answer
141 views

Does Simple Injector have a feature like Autofac Factory Delegates?

Consider the scenario where a service's constructor has a mix of parameters: some you want the container to resolve based on whatever you registered, and some you want the consumer of the service to ...
1 vote
1 answer
65 views

Registering multiple AmazonS3Clients in SimpleInjector and configuring Adapter

The issue is as follows: I have to access 2 different S3 buckets and the way I have to create AmazonS3clients is as follows: var client = new AmazonS3Client(accesKey,secretKey, bucketRegion); Since I ...
  • 2,159
0 votes
1 answer
221 views

Is there a way to conditionally register types as fallback with .NET dependency injection?

We currently use SimpleInjector as our DI container to implement the command-query-separation (CQS) pattern by using ICommand and IQuery<TResult> and ICommandHandler<TCommand> and ...
  • 2,679
0 votes
0 answers
48 views

Registering a generic resolver for Repository with Simple Injector

I have the following repository which is a generic with two-parameter public interface IClownRepository { } public interface IClownRepository< TEntity> : IClownRepository<...
  • 3,479
2 votes
1 answer
123 views

Simple Injector. How to reuse a decorator class more than once in object's decorator chain using Scoped lifestyle

I want to reuse same class more than once in a chain of decorated objects like this. InstrumentedTargetDecorator -> ResilientTargetDecorator -> InstrumetedTargetDecorator -> Target Note that ...
1 vote
1 answer
97 views

Registering a MassTransit SagaStateMachine with RedisRepository in SimpleInjector - Multiple Constructors

I am able to register a MassTranst SagaStateMachine in a SimpleInjector container using the InMemoryRepository: container.AddMassTransit(cfg => { // Unrelated registration code ommitted // ....
  • 11
3 votes
0 answers
417 views

How to inject cancellation token in a HostedService timer with Simple Injector

I'm trying to create a console application that run ahosted service with Simple Injector and I looked to the example at generichostintegration. Now I would like to change IProcessor.DoSomeWork to be ...
  • 31
0 votes
0 answers
115 views

How to use a DI Container within a legacy class to create an instance of a new class

There is a legacy class in a huge Winforms solution which I cannot change the constructor (because there are lots of references to it). However, I need to call a new class method within one of the ...
  • 966
0 votes
1 answer
141 views

Azure Function throws SimpleInjector.ActivationException in "stress test"

We have a couple of functions in a function app based on a consumption plan. When I stress test these functions with JMeter (200 threads simultaneously), the functions are throwing SimpleInjector....
  • 292
1 vote
1 answer
476 views

Simple Injector Property Injection in User Control Windows Forms

I have to create a small app that uses windows forms. I want to use Simple Injector as IoC Container. Documentation of Simple Injector wrote: It is not possible to use Constructor Injection in User ...
1 vote
1 answer
684 views

HttpClientFactory with default Polly policy handler registration and injection with SimpleInjector

Per https://github.com/App-vNext/Polly/wiki/Polly-and-HttpClientFactory#extending-the-convenience-addtransienthttperrorpolicy-definition I can see policies are added with a name. var httpClientOptions ...
  • 2,087
0 votes
1 answer
693 views

Simple Injector and Mapster Dependency Injection setup

The documentation on the Mapster Wiki isnt very good and I cant seem to get it hooked up with Simple Injector. I have this below: container.RegisterSingleton(() => MapperProvider....
  • 22.2k
0 votes
1 answer
307 views

Automapper 10 and Simple Injector v5 setup "SimpleInjector.ActivationException"

I am following this setup below in the AutoMapper setup article but I keep getting this error. Is the documentation incorrect? private static IMapper GetMapper(Container container) { var mp = ...
  • 22.2k
1 vote
1 answer
528 views

You are trying to resolve a cross-wired service, but are doing so outside the context of an active (Async Scoped) scope with Simple Injector

I'm building a .NET Core console app that uses Simple Injector and SimpleRabbit to pubish messages to RabbitMQ. I've run into a run time exception when I attempt to get an registered instance from a ...
  • 3,735
1 vote
1 answer
298 views

Simple Injector throws an error in Caliburn.Micro Bootstrapper.Buildup when calling async method in the viewmodel

I am trying to use Simple Injector as the DI container for Caliburn.Micro. Demo source: https://github.com/nvstrien/WPFDemos This project has a basic Caliburn.Micro setup with a Simple Injector ...
1 vote
1 answer
518 views

Simple Injector, dependency injection of services and multiple instances

I am using Simple Injector for my DI library. I have controllers in my asp.net MVC site that take services in their constructors via this library. When I look at the Diagnostic Tools in Visual ...
  • 22.2k
1 vote
0 answers
171 views

How do I use a SimpleInjector container with HostBuilder?

I'm building .NetCore console app which uses SimpleRabbit (RabbitMQ). I am attempting to use HostBuilder() to this purpose (dependecy injection, configuration, services). I create a SimpleInjector ...
  • 3,735
1 vote
2 answers
323 views

Simple Injector explicit attribute injection - property is null inside constructor

New to Simple Injector, trying to get some pieces working for a prototype. I am creating a WPF application that uses Simple Injector and ReactiveUI, but can't seem to get explicit property injection ...
  • 13
0 votes
1 answer
388 views

Simple Injector LoggerFactory in IHostBuilder.ConfigureServices bootstrap

I am using Simple Injector with the generic hosts nuget package, all is well except I have hit a snag with order of registration. I have a builder class that returns two interfaces, IMessagePublisher ...
  • 2,087
1 vote
1 answer
165 views

How do I build tests using xUnit for an Asp.NetCore WebAPI built with Entity Framework Core and Simple Injector?

I have created an ASP.NET Core Web API using Entity Framework Core and Simple Injector. I would like unit tests using xUnit to test my controllers. I'm not sure where to begin. I believe that I have ...
  • 3,735
0 votes
1 answer
1k views

How do I access AppSettings.json fie in the DBContext of a .NET Core WebApi using Entity Framework Core and Simple Injector?

I am building an ASP.NET Core WebApi service using Entity Framework Core and the Simple Injector IoC Container. The application use a postgresql DB via Npgsql.EntityFrameworkCore.PostgeSQL. Here is a ...
  • 3,735
1 vote
1 answer
227 views

Auto-registration of generic classes

I'm trying to inject a generic class with Simple Injector. However, it fails with SimpleInjector.ActivationException: No registration for type ... could be found Here's the code to reproduce it: ...
  • 1,040
0 votes
1 answer
194 views

Simple Injector and unit test?

We mainly use class injections theses days and that works great with unit test but there is some(a lot) of code that makes calls directly to the container and this results in problems while running ...
  • 15.2k
0 votes
0 answers
89 views

Simple Injector is missing one of the open generic types after it is registered - what might be happening?

I'm having some difficulty with registering some open generic types with simple injector. In startup I am registering in the following way.. var assemblies = LoadAssemblies("MyProjectName");...
  • 105
1 vote
1 answer
890 views

IServiceProvider that is not registered

When the application starts the error occurs The constructor of type ImportExportController contains the parameter with name 'serviceProvider' and type IServiceProvider that is not registered. Please ...
0 votes
0 answers
318 views

.NET Core Identity and Simple Injector. Crosswire not working

I am using simple injector (4.8.1) on a project that uses asp.net core identity. I tried to crosswise UserManager but I got an error saying No service for type 'Microsoft.AspNetCore.Identity....
  • 125
0 votes
1 answer
337 views

How to add all registered services from Blazor to Simple Injector?

I have a server side blazor application and I'm also using simple injector for other dependency injections in my application. I want to register all services from blazor to the simple injector ...
  • 26.9k

1
2 3 4 5
23