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.
1,103
questions
0
votes
1
answer
221
views
Find implementation of generic interface
I am registering classes dynamically from an assembly, a bunch of command handlers:
class class DummyCommand : ICommand {}
class GetAgeCommandHandler : ICommandHandler<DummyCommand>
{
...
1
vote
1
answer
139
views
Simple Injector - Creating Module
I want to change my DI library autofac to simple injector.
I have a module in my business layer which is keeping registration for data access and business layer registrations. And I register this ...
3
votes
1
answer
916
views
How to properly configure Simple Injector with FluentScheduler
I have following configuration for Simple Injector.
public class SimpleInjectorIntegrator
{
private static Container container;
public static Container Setup()
{
container = new ...
0
votes
1
answer
397
views
How do I use multiple types with the same interface in different scenarios with SimpleInjector?
Let's say (not necessarily with DI) I have an interface to do something, and two different classes implementing it (doing different "somethings"):
public interface ISomethingDoer {
void ...
6
votes
3
answers
2k
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-...
1
vote
0
answers
253
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<T> : IPriceCalculator<T>
...
0
votes
0
answers
101
views
What is the best way to handle Websharper Remoting Singletons while using Simpleinjector with potentially Scoped Dependencies?
I'm trying to Convert an application I have working under a Basic Websharper Setup into an ASP.NET Core Application, Using Simple Injector for DI, but Cannot get the Configuration quite right. I think ...
1
vote
1
answer
661
views
Using SimpleInjector scopes in SpecFlow 3 life cycle hooks
I'm trying to setup my Specflow (V. 3.0.155 beta) tests in a .Net Core 2.1 Web API and I'm following a structure I've used in some previous .Net Framework Web API projects I've worked on to do so.
...
4
votes
1
answer
457
views
Inject dependency dynamically based on call chain using simple injector
In my application, I want to construct the following object graphs using my DI Container, Simple Injector:
new Mode1(
new CommonBuilder(
new Grouping(
new GroupingStrategy1()))...
1
vote
2
answers
3k
views
ASP.NET Core 2.1 Service Locator with Simple Injector returning null
I have an .NET MVC 5 .NET Framework Application which I am converting to .NET Core 2.1
I have a custom action filter which in .NET Framework version was registered as a Global Filter in a ...
1
vote
1
answer
685
views
Simple Injector: Decorator for multiple interfaces
I have the following inheritance I want to decorate with Simple Injector (renamed stuff to make it more readable):
interface IGetData<T,U> { }
interface ICustomerService : IGetData<Customer, ...
2
votes
1
answer
1k
views
Transient component is registered as transient but implements idisposable
I use Simple injector but somehow i get error as stated in subject. I tried many things before i decided to post this question for instance this is not working for me. I get the following exception ...
0
votes
1
answer
55
views
WebApi Controller Method with SimpleInjector not adding records to database
On my form I am using ajax to submit the form to my API controller method for creating new objects. In my API controller, I am using SimpleInjector for Dependency Injection but for some reason when ...
1
vote
1
answer
334
views
Runtime Null Reference Exception Using SimpleInjector in WebApi Controller
In my MVC project, I have an API controller that I want to use dependency injection for. I am using Simple Injector for dependency injection.
Here is my api controller:
public class ...
1
vote
1
answer
207
views
simple injector - inject into IHttpHandler
I'm trying to embed SimpleInjector in my WCF project (I've followed the instructions here). Till now everything went well except from IHttpHandler issue:
the current implementation uses IHttpHandler ...
1
vote
1
answer
418
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 ...
2
votes
1
answer
2k
views
Options pattern, configuration, in Legacy .NET Application with Simple Injector
This article, https://medium.com/@dmitryzaets/legacy-net-applications-configuration-management-net-framework-4-5-1-68220335d9d8, describe how to use Options pattern together with Autofac. I have tried ...
2
votes
3
answers
1k
views
SharedResource Localization and Simple Injector in asp.net core 2.1
I have an ASP.NET web api in ASP.NET core 2.1 and I have implemented a shared resource as explained here. This works fine.
The line :
services.AddLocalization()
adds localization to the inbuilt IOC ...
1
vote
1
answer
727
views
Re-use scoped ILogger instance from Azure Function
I'm not sure what is the best way to achieve what I am trying to accomplish so let me give you an example.
I am using Azure Functions, which are stateless, with the following signature.
public ...
0
votes
0
answers
520
views
Getting an exception "Cannot access a disposed object." when performing second operation on the same mvc page
I have an MVC 5 application that is using for some part EF Core to access the database. I'm using SimpleInjector and Repository pattern.
I've registered my MainContext as
container.Register(() => ...
1
vote
1
answer
86
views
Error using Simple Injector inside OAuth GrantResourceOwnerCredentials method
I am using Simple Injector in my ASP.NET WEb API project to dependency injection and OAuth for authentication. For that, I need to resolve an interface inside the GrantResourceOwnerCredentials method, ...
1
vote
2
answers
423
views
Simple Injector with multiple WebAPI projects
I have a C# solution that includes multiple WebAPI projects. One of these projects, let's call it Project A, already uses SimpleInjector successfully. I'm trying to add SimpleInjector to another of ...
3
votes
2
answers
906
views
Simple Injector gives lifestyle mismatch error while both classes are registered as singleton
So I have this Simple Injector IoC wire up code
container.RegisterSingleton<IMsgProcessor, PrometheusTickerPublisher>();
container.RegisterSingleton<ICollector, UpdatesPerSecondDataCollector&...
4
votes
1
answer
331
views
Binary PowerShell Core cmdlet using SimpleInjector results in FileNotFoundException
The Question
I'm trying to create a PowerShell Core binary cmdlet library that uses SimpleInjector, but cannot figure out why it's resulting in a FileNotFoundException when debugging it with Visual ...
0
votes
1
answer
266
views
Integrate Simple Injector into MVC 5 site that also has some Web Api 2 controllers
I have an ASP.NET MVC 5 project, using the default template which uses ASP.NET Identity 2. You know, the one with that awful poor's man dependency injection using OwinContext and the AccountController....
0
votes
0
answers
58
views
Ninject named scoped equivalent in Simple Injector
We use a hierarchy of different custom named scopes with Ninject in our
application. But we have been suffering from performance issues with this framework for some time and would like to replace it ...
0
votes
1
answer
54
views
Registering class by multiple abstractions while creating the type by hand
I want to register class Foo and its interface IBar.
var b = new DbContextOptionsBuilder();
b.UseSqlServer(@"Server=(localdb)\MSSQLLocalDB;Database=Connect.Device;Trusted_Connection = True; ...
1
vote
1
answer
1k
views
Simple injector how to register /resolve collection of singletons against same interface
So I have this class that I would like to register multiple singletons off, where I would like to distinguish between them (after resolving from container) using the "ExchangeName" property
public ...
0
votes
0
answers
2k
views
Dependency Injection with Simple Injector and .Net Core
I am running into an error 'Unable to resolve service for type 'MassTransit.IBusControl' while attempting to activate 'PCNDmzWeb.Api.Services.MassTransitHostedService'.'"
I am using the boilerplate ...
0
votes
2
answers
117
views
ViewModel and View not getting bound for user control in listbox
I have a BooksListViewModel & BooksListView which have just a list box named Books which should be populated via the BindableCollection<BookViewModel> Books property in the ViewModel.
...
2
votes
1
answer
87
views
Registering open-generic decorators through a single binding rule
Trying to use Command/Handler pattern and Aspect Oriented Programming with Simple Injector.
I have my command and handler classes.
ICommandHandler.cs
public interface ICommandHandler<TCommand>...
0
votes
1
answer
72
views
how to resolve a type safe collection in the constructor?
I have this object structure
public interface IHandler<in TMessage>
{
void HandleMessage(TMessage messageType);
}
public class MessageType1
{
}
public class MessageType2
{
}
public class ...
2
votes
3
answers
1k
views
Simple Injector integration with HostBuilder in .NET Core 2.x
We are developing a windows service that runs .net core 2.x. Following this blog post by Steve Gordon running .netcore generic host applications as a service things seem to be working beautifully... ...
0
votes
0
answers
60
views
How to use Generic Interface in SimpleInjector when registering new TService?
I have simple interface:
public interface IRepo<T>
{
T GetSingle(int id);
IQueryable<T> GetCollection();
}
And few implementation of this interface:
public class ...
0
votes
1
answer
567
views
How to depenency injection/register open generic types
I have a microservices architecture using simple injector in each service. The services communicates through Azure Service Bus. I'm currently trying to find a way to implement a generic solution/...
1
vote
0
answers
171
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 ...
6
votes
3
answers
12k
views
Using Entity Framework Core DbContext Pooling with Simple Injector
Looking at the examples of how to use db context pool I see it was designed to be used with ServiceCollection:
var serviceProvider = new ServiceCollection()
.AddDbContextPool<...
0
votes
0
answers
105
views
Getting a new (separate) instance of an object that is registered as "per request"
I have a service (in this case, a database context wrapper) that is registered with my SimpleInjector container as "per request", meaning that anything that I inject into will get the same instance ...
2
votes
1
answer
250
views
Simple Injector: RegisterWebApiController failing to suppress DisposableTransientComponent warning
I may be simplifying or misunderstanding things, so I'd like to apologise in advance if this is a really dumb question. :)
Based on the documentation and code I've seen, my understanding is that when ...
2
votes
1
answer
1k
views
Inject Logger in IExceptionFilter with SimpleInjector
I'm using Simple Injector in an ASP.NET Core 2.1 WebAPI application. I have an IExceptionFilter in which I want to log the error. My code is below (working), but is this the correct way? It looks like ...
1
vote
2
answers
62
views
Getting parameterles public constructor error
An error occurred when trying to create a controller of type
'ChatBotController'. Make sure that the controller has a
parameterless public constructor.
at
System.Web.Http.Dispatcher....
0
votes
1
answer
1k
views
Simple Injector w/ ASP.Net Core 2.0 IOptionsSnapshot injection
I was trying what was suggested in bug #429 and am getting the same error he reported there but then never provided the stack trace for. I have also read, and have used until recently, your guidance ...
1
vote
1
answer
641
views
Getting lifestyle mismatch registered as transient but implements idisposable error
I am trying to inject the API dependency and MVC dependency. But when I try to inject the MVC Dependency I get the error:
The configuration is invalid. The following diagnostic warnings were
...
1
vote
2
answers
205
views
Preventing the User Interface Layer from Depending on the Data Access Layer
I have 3 projects in .NET
DAL (data access layer)
UI (user interface)
BI ( logic)
DAL call the BI (services)
And The BI Call the DAL (repository)
my problem in my UI project in (global.asax)
- I ...
2
votes
1
answer
95
views
Catalog concept instead of complex constructors?
In my current project my manager is forcing some design concept for dependency injection I would like to discuss because I’m curious what a specialists of dependency injection think about this ...
0
votes
1
answer
742
views
How to inject list of base interfaces to class
I have a program where I have some services with custom interfaces but all of them inherit from IService. The services are registered with their custom interfaces as singletons in Simple Injector ...
0
votes
1
answer
46
views
Verify forces lazy initialization of services
Firstly, thank you- I have become a better programmer by being "forced to" by Simple Injector.
Very early in the bootstrap of my program I setup my root container and shortly afterward call container....
0
votes
0
answers
180
views
using simple injector with aspnet.identity
I'm trying to use simple injector with my mvc project, and I'm unclear how to complete all registrations for framework code. In particular, with this aspnet.identity code.In general, since this isn't ...
1
vote
1
answer
2k
views
Creating custom Simple Injector Scope in Web Forms
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 ...
0
votes
1
answer
493
views
Is it okay to use a static Simple Injector DI container in my Azure Function?
I have a Simple Injector DI Container which helps instantiate the various dependencies I'll need for my function. I know static variables have special treatment in Azure Functions and I want to make ...