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,101
questions
6
votes
1
answer
4k
views
Using dependencies on multiple threads with Parallel.ForEach
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<IWebRepository, ...
15
votes
2
answers
7k
views
Simple Injector: Registering a type with constructor argument that's based on its parent
I am currently in the process of removing Ninject from my project, and moving to using Simple Injector but there is one thing that I can not get working properly.
For my logging, in the registering ...
8
votes
1
answer
3k
views
Use different configurations with Simple Injector
I'm using the Simple Injector Dependency Injection framework and it looks cool and nice. But after building a configuration and use it, now I want to know how to change from one configuration to ...
3
votes
1
answer
813
views
Mocking ApiController which has Unit of work Dependency
I have a Apicontroller Which has dependency on unit of work object. How to write a test case for mocking ApiController Which has dependency on unit of work implemented in ApiController constructor.
...
9
votes
1
answer
5k
views
Simple Injector pass hard coded values into constructor
In Simple Injector I can do the following:
container.RegisterSingle<IAuctionContext>(() => new AuctionContext(
new Uri("http://localhost:60001/AuctionDataService.svc/")));
What I am ...
4
votes
1
answer
2k
views
Can SimpleInjector register an initializer for generic types at runtime?
Can I register initializers for Generic types with SimpleInjector at runtime? (see the last line of code below)
public class BootStrapper
{
Type baseTypeGeneric = typeof(Sample<>);
...
2
votes
1
answer
1k
views
Multiple RegisterAll registrations using the same set of singletons with SimpleInjector
I'm building a plugin system for an e-commerce project with Simple Injector. I'm using RegisterAll to register all implementation of a IPaymentProvider and of a IResourceRegistrar (and in the fure ...
1
vote
1
answer
810
views
How to return an instance based on its parent using Simple Injector?
We have been using Windsor Castle as our DI Container but we are looking around for alternatives. Now I got to the Simple Injector and so far I have been impressed by its simplicity but one scenario I ...
8
votes
2
answers
2k
views
How to use SimpleInjector in a multi project solution without creating circular references
I’m starting a multi project solution that will have more than one entry point, for example a Windows Service, ASP.NET web sites, WebApi Controllers etc. I’ve settled on SimpleInjector as it’s very ...
1
vote
1
answer
744
views
Architecture for stateful MVVM application with self contained client-server code and IoC container
I have an application which has multiple screens and talks to a WCF web service. I am using SimpleInjector for my favourite IoC container, and Caliburn Micro for MMVM with WPF.
I have a separate ...
1
vote
1
answer
636
views
Simple Injector async life time scoping and security exception
I have a AsyncCommandHandlerDecorator<TCommand> and LifetimeScopedCommandHandlerDecorator<TCommand> as shown below:
public class AsyncCommandHandlerDecorator<TCommand>
: ...
1
vote
4
answers
455
views
Chaining layers with IoC, setting lower callback to upper and avoid circular reference
I have a scenario where I need a lower layer to be controlled by an upper layer much like a puppet master pulling on strings.
The lower layer also will call back to the upper layer as some internal ...
2
votes
1
answer
1k
views
Simple injector open generic decorators
I am trying to make use of some of the nice features in simple injector.
I am currently having problems with the decorators, they are not getting hit when I expect them too.
I am registering them ...
1
vote
1
answer
929
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 ...
2
votes
1
answer
3k
views
command pattern using Dependency Injection for MVC 3 controller
I read the following article .NET Junkie - Meanwhile... on the command side of my architecture which was suggested by another stackoverflow user that outlines the command pattern and provides a ...
14
votes
1
answer
6k
views
Mixed lifestyle for Per Thread and Per Web Request with Simple Injector
I'm using SimpleInjector as my IoC library. I register DbContext as per web request and it works fine. But there is one task that I run it in a background thread. So, I have a problem to create ...
2
votes
1
answer
2k
views
SimpleInjector - Register a type for all it's interfaces
Is it possible to register a type for all it's implementing interfaces? E.g, I have a:
public class Bow : IWeapon
{
#region IWeapon Members
public string Attack()
{
return "...
3
votes
2
answers
647
views
Conditional registering a command decorator based on generic type constraints in SimpleInjector
How to register a conditional decorator in SimpleInjector? Here are my definitions:
public interface ICommand { }
public interface ICleanableCommand : ICommand {
void Clean();
}
public ...
0
votes
0
answers
515
views
simple injector ASP.NET MVC post form result error
I'm new with simple injector, register all instances as described in guide on codeplex and nuget package. All works fine when I'm clicking on links, which relates to actions without form back result.
...
1
vote
1
answer
208
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 ...
8
votes
1
answer
2k
views
Simple Injector registering IMappingEngine (AutoMapper)
I used Autofac before but now I want give SimpleInjector a try. My problem is, on calling the mappingEngine within my method I get the following error:
Missing type map configuration or unsupported ...
6
votes
2
answers
9k
views
Simple Injector property injection on action filter
The action filter I want to inject into starts like this
public class UserAuthorisation : AuthorizeAttribute
{
public IWcfClientProxy<IAppFrameworkServiceChannel>
...
6
votes
1
answer
3k
views
How to change dependency registration at run time using simple injector?
I'm using the Simple Injector IoC framework, and I would like to be able to change the dependency registration at run time. For example, I have two implementations, A and B, of interface I. ...
8
votes
3
answers
1k
views
How to reduce number of injected dependencies on controller
I am using MVC3, Entity Framework v4.3 Code First, and SimpleInjector. I have several simple classes that look like this:
public class SomeThing
{
public int Id { get; set; }
public string ...
2
votes
2
answers
697
views
Caliburn binding exception
Let me explain my problem. Please excuse me for the long question.
Here it goes.
I have a View (BusyProviderView)
<Grid>
<xctk:BusyIndicator x:Name="aaa" IsBusy="{Binding IsRunning}" &...
3
votes
1
answer
4k
views
how can I register a custom ModelMetadataProvider with Simple Injector in mvc3
when I try to register the model metadata provider with simple injector I don't get any error but when I access the instance is the one by default in mvc.
the way that I'm trying to register the ...
5
votes
1
answer
3k
views
Replace Ninject with Simple Injector
I've used Ninject for my application. Ninject is really simple and easy to learn, but its quite slow and I try to use another IoC to compare if its faster as with Ninject.
There are a lot of IoC ...
8
votes
1
answer
3k
views
Where's Simple Injector's equivalent of StructureMap's ObjectFactory
I am in the process of migrating from StructureMap to Simple Injector in a ASP.NET MVC3 application.
I am using the MVC3 extension for controller DI, but I am running into an issue with trying to ...
3
votes
1
answer
1k
views
Cannot retrieve Entity Framework Object Context for Verification in SimpleInjectorInitializer
It seems that when I installed the Simple Injector MVC3 Integration package, SimpleInjectorInitializer was placed in the App_Start folder. However, when the Verify() method is called within Initialize(...
3
votes
1
answer
2k
views
SimpleInjector: Injection does not work with MVC 4 ASP.NET Web API
I have this setup:
public static void Initialize(ISessionFactory factory)
{
var container = new Container();
InitializeContainer(container, factory);
container.RegisterMvcControllers(
...
17
votes
2
answers
7k
views
Does Simple Injector supports MVC 4 ASP.NET Web API?
I am new to Simple Injector IOC container. I will start working in a project which will require a Multi-tenant ASP.NET MVC implementation using MVC 4 ASP.NET Web API.
My question is: Does Simple ...
1
vote
1
answer
525
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 ...
1
vote
1
answer
918
views
IoC Task Scheduler Design with Simple Injector with code example recommendations
Hi I am using Simple Injector and I am trying to implement a scheduler service which calls command(s) at a programmable regular frequency. My design decisions are below:
1) I have a service that runs ...
5
votes
3
answers
5k
views
Unable to Create DbContext per Request with Simple Injector
Simple Inject is throwing the following exception when attempting to register my DbContext.
The supplied connection string is not valid, because it contains insufficient mapping or metadata ...
8
votes
2
answers
5k
views
How to configure Simple Injector to run background threads in ASP.NET MVC
I am using Simple Injector to manage the lifetime of my injected dependencies (in this case UnitOfWork), and I am very happy as having a separate decorator rather than my service or command handler ...
4
votes
1
answer
1k
views
Simple Injector using different decorators for different commands
Hi I am starting to use Simple Injector DI container for all my projects and would like some advice on how to fit is powerful features to my requirements.
I have a couple of command handler ...
8
votes
1
answer
5k
views
Simple Injector: Inject same UnitOfWork instance across services of the same graph
I have multiple services, each of which have a UnitOfWork injected into the constructor using the Simple Injector IoC container.
Currently I can see each UnitOfWork instance is a separate object, ...
5
votes
1
answer
2k
views
How to configure Simple Injector IoC to use RavenDB
I'm using Simple Injector for an IOC in an MVC 3 web application. I am using RavenDB for the data storage. There are several considerations on using RavenDB in an mvc 3 application. I've searched some ...
35
votes
6
answers
14k
views
Using Simple Injector with SignalR
I thought using my own IoC would be pretty straight forward with SignalR and maybe it is; most likely I'm doing something wrong. Here's my code I have so far:
private static void InitializeContainer(...
3
votes
1
answer
1k
views
Is this the right way to RegisterDecorator when some types have no implementation?
Using simple injector with the command pattern described here. Most commands have companion classes that implement fluent validation's AbstractValidator<TCommand>, which means they also ...
5
votes
1
answer
3k
views
Simpleinjector: Is this the right way to RegisterManyForOpenGeneric when I have 2 implementations and want to pick one?
Using simple injector with the command pattern described here and the query pattern described here. For one of the commands, I have 2 handler implementations. The first is a "normal" implementation ...
2
votes
1
answer
1k
views
SimpleInjector does not inject property using Implicit Property Injection
I have an ObjectA, which has a property for ObjectB, which has a property for ObjectC, which are all in the Simple Injector container. When I create ObjectA, I call InjectProperties on it, which ...
5
votes
1
answer
4k
views
Prevent Simple Injector to throw an exception when resolving an unregistered service
I was wondering if Simple Injector has an option to stop throwing exceptions whenever GetInstance(Of TService) returns Nothing? It appears to be throwing them now because I have two requests to get ...
7
votes
1
answer
9k
views
What is the correct way to register FluentValidation with Simple Injector?
I am able to register FluentValidation AbstractValidators using a FluentValidatorFactory. However, it doesn't feel right, because not all of the IoC container registrations happen during bootstrap / ...
3
votes
1
answer
2k
views
EF DbContext per web request + Custom RoleProvider = RoleProvider per web request or singleton?
Using EF DbContext wrapped in interface(s), dependency injected per web request, to make sure the entire request deals with the same context. Also have a custom RoleProvider which consumes the ...
3
votes
2
answers
2k
views
How to do open generic decorator chaining with unity + UnityAutoRegistration
Went off on an interesting tangent today after reading this article on command handler decoration. I wanted to see if I could implement the pattern using Unity instead of SimpleInjector, and so far it ...
1
vote
2
answers
159
views
How to register a TImpl that has one moregeneric type parameter than TService in SimpleInjector?
I am doing the following right now
container.Register<IDatabaseMapper<User>, DatabaseMapper<User, OracleException>>();
container.Register<IDatabaseMapper<Desk>, ...
15
votes
1
answer
4k
views
How can I emulate Modules / Installers / Registries with Simple Injector
Autofac has modules, Windsor has Installers and StructureMap Registries ... with Simple Injector how can I pack configuration logic into reusable classes?
I have tried:
public interface IModule { }
...
46
votes
1
answer
18k
views
Simple Injector vs Hiro vs Autofac [closed]
I'm new to DI and IoC and I'm trying to decide which IoC container to learn. I've seen several performance comparisons in which the three containers referenced seem to perform very well. However, I ...
1
vote
1
answer
1k
views
Simple Injector: RegisterInitializer does not always fire
I use the RegisterInitializer method to inject properties in base types as follows:
container.RegisterInitializer<BaseHandler>(handler =>
{
handler.Context = container.GetInstance<...