1,115 questions
0
votes
0
answers
72
views
Could not load file or assembly 'SimpleInjector' or one of its dependencies after updating SimpleInjector to 5.5.0
I have a .net framework 4.8 project. In my solution, there are a lot of projects. Some of these projects use the SimpleInjector library. Recently I have updated all the packages to the latest version (...
0
votes
0
answers
96
views
How to Convert RegisterDecorator from Simple Injector to .NET Core's IServiceCollection?
I'm trying to migrate some code from Simple Injector's RegisterDecorator pattern which is in .Net Framework to .NET Core's IServiceCollection. In Simple Injector, my code looks like this:
container....
1
vote
3
answers
128
views
Polymorphic DI framework or setup for .NET?
The situation that I have is the following and albeit quite simple, it seems not to be supported (at least out of the box) for 2 DI frameworks that I tried.
public interface IPlugin
{
// misc
}
...
0
votes
1
answer
57
views
Same Lifestyle of classes but still mismatch error from simpleinjector
I try register collection of implementations but everytime I get error message
"-[Lifestyle Mismatch] ReportFileWriter (Singleton) depends on IFileWriter[] (Transient)."
I dont know what ...
0
votes
0
answers
61
views
SimpleInjector. How to resolve instances which has parameters that could be evaluated only in runtime
I have a lot of objects in my program that are created at runtime with at least 1 parameter. There are many nested classes where a new data is evaluated, which is necessary for next inner instances.
...
2
votes
1
answer
58
views
SimpleInjector: how to register proxy class for several interfaces at once
I'm developing a Telegram bot. And I'm struggling with SimpleInjector class registration.
I need to register a class ProxyBotMesssageSender as a proxy for BotMesssageSender class that implements 3 ...
0
votes
0
answers
35
views
Simple Injector: Best way to batch-register CQRSlite event handlers
In a project I am using CQRSlite and Simple Injector. My first try to register the event handlers:
container.Register(typeof(ICancellableEventHandler<>), typeof(...
0
votes
0
answers
143
views
Problem registering two instances of IEnumerable<Type>
I have a problem with SimpleInjector and I don't know how to resolve it. I'm getting the following error:
The configuration is invalid. Creating the instance for type IMiddleware failed. The ...
0
votes
1
answer
142
views
Getting all registered types inheriting from a generic interface from the container
I am using Simple Injector 5.3.3 and I would like to access at run time to a list of the types inheriting from a generic interface (say IHandleMessage<T>) that I registered in the container. How ...
0
votes
1
answer
90
views
Is it possible to set a timeout on Simple Injector
Is it possible to set a timeout on Simple Injector when creating an instance?
For example, I had a problem in the past when I instantiated an HTTPClient and the base URL was collected by a query in ...
1
vote
1
answer
331
views
SimpleInjector MediatR scope lost
Within a Blazor server application I do use the Simple Injector integration as well as the MediatR. The Simple Injector looks like it works pretty fine together with Blazor with respect to the scoping,...
0
votes
1
answer
209
views
AutoMapper doesn't use SimpleInjector activator
All of this is on .NET 6, AutoMapper v12, SimpleInjector v5.4.1
Upon trying to map to IModel (interface of Model), code throws the following stack trace:
AutoMapper.AutoMapperMappingException: Error ...
0
votes
1
answer
166
views
Simple Injector creating instances of controllers on calling container.Verify()
I'm using Simple Injector with Owin Selfhosted, but I'm having a problem on calling container.Verify().
When I call container.Verify(), it is creating an instance of all my controllers, but in some of ...
1
vote
2
answers
140
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 ...
0
votes
1
answer
173
views
Simple Injector - Registering plugins dynamically with constructor values from config
According to the documentation of Simple Injector one can use the following code to load assemblies dynamically
string pluginDirectory =
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "...
0
votes
1
answer
68
views
Simple Injector Creates Controller Multiple Times and Creates Unnecessary Controller
I noticed a strange behavior when using Simple Injector 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, ...
0
votes
1
answer
159
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....
0
votes
1
answer
230
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 ...
0
votes
2
answers
98
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 ...
2
votes
1
answer
807
views
Simple Injector 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
392
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
213
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....
0
votes
1
answer
173
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
274
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<...
2
votes
1
answer
884
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 ...
0
votes
1
answer
615
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 ...
0
votes
1
answer
758
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 ...
0
votes
0
answers
115
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 ...
0
votes
0
answers
255
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 ...
0
votes
1
answer
508
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 ...
0
votes
0
answers
79
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<...
0
votes
0
answers
82
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 ...
1
vote
1
answer
529
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<>),
...
0
votes
1
answer
1k
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
193
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'...
1
vote
1
answer
452
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....
1
vote
1
answer
299
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
201
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 ...
1
vote
1
answer
577
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 ...
0
votes
0
answers
71
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<...
2
votes
1
answer
252
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
229
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
// ....
3
votes
0
answers
1k
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 ...
0
votes
0
answers
259
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 ...
0
votes
1
answer
237
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....
1
vote
1
answer
849
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
2k
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 ...
0
votes
1
answer
1k
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....
0
votes
1
answer
490
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 = ...
1
vote
1
answer
1k
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 ...