SimpleInjector | fast Dependency Injection | Dependency Injection library

 by   simpleinjector C# Version: v5.4.1 License: MIT

kandi X-RAY | SimpleInjector Summary

kandi X-RAY | SimpleInjector Summary

SimpleInjector is a C# library typically used in Programming Style, Dependency Injection applications. SimpleInjector has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

An easy, flexible, and fast Dependency Injection library that promotes best practice to steer developers towards the pit of success.

            kandi-support Support

              SimpleInjector has a medium active ecosystem.
              It has 1135 star(s) with 145 fork(s). There are 62 watchers for this library.
              It had no major release in the last 12 months.
              There are 34 open issues and 894 have been closed. On average issues are closed in 122 days. There are 1 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of SimpleInjector is v5.4.1

            kandi-Quality Quality

              SimpleInjector has 0 bugs and 0 code smells.

            kandi-Security Security

              SimpleInjector has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              SimpleInjector code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              SimpleInjector is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              SimpleInjector releases are available to install and integrate.
              Installation instructions, examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of SimpleInjector
            Get all kandi verified functions for this library.

            SimpleInjector Key Features

            No Key Features are available at this moment for SimpleInjector.

            SimpleInjector Examples and Code Snippets

            No Code Snippets are available at this moment for SimpleInjector.

            Community Discussions


            Multiple Hosted Service With Simple Injector
            Asked 2022-Mar-05 at 09:29

            i'm trying to follow this example here

            the only thing is i need to inject multiple hosted services instead of one like this



            Answered 2022-Mar-05 at 09:29

            I'm unable to reproduce your issue. I used the following code in a Visual Studio 2022 ASP.NET Core MVC 6 project:



            Simple Injector. How to reuse a decorator class more than once in object's decorator chain using Scoped lifestyle
            Asked 2022-Jan-29 at 16:13

            I want to reuse same class more than once in a chain of decorated objects like this.

            InstrumentedTargetDecorator -> ResilientTargetDecorator -> InstrumetedTargetDecorator -> Target

            Note that InstrumentedTargetDecorator is used twice here on purpose.

            This is how SimpleInjector syntax looks to get the above wired up



            Answered 2022-Jan-29 at 16:13

            You encountered a bug in Simple Injector. I will try to fix this in the next patch release. This bug has been fixed in v5.3.3.

            As workaround, when working in an older release, create a derivative of the decorator inside your Composition Root and make that derivative the second registration. Hopefully this suppresses the invalid warning:



            Equivalent Simple Injector .Register invocations
            Asked 2021-Dec-23 at 09:46

            I have an object whose constructor requires a primitive. I register it using a delegate (please excuse the contrived example).



            Answered 2021-Dec-23 at 09:46


            Registering multiple AmazonS3Clients in SimpleInjector and configuring Adapter
            Asked 2021-Nov-22 at 13:05

            The issue is as follows:

            I have to access 2 different S3 buckets and the way I have to create AmazonS3clients is as follows:



            Answered 2021-Nov-22 at 13:05

            Here is the way to do it thanks to @Steven:



            Is there a way to conditionally register types as fallback with .NET dependency injection?
            Asked 2021-Nov-02 at 08:14

            We currently use SimpleInjector as our DI container to implement the command-query-separation (CQS) pattern by using ICommand and IQuery and ICommandHandler and IQueryHandler interfaces.

            We also use the decorator pattern to perform aspect-oriented programming. For one of our decorators we use FluentValidation to perform validation logic for specific commands or queries.

            With SimpleInjector, it is possible to conditionally register types. This is useful for our FluentValidation decorator when we have a command or query which does not have a corresponding validator. Then we use a NullValidator as fallback which does nothing. Exactly this scenario is described in the SimpleInjector documentation and looks like this for the FluentValidation scenario:



            Answered 2021-Nov-02 at 08:14

            I managed to work around this issue by injecting an IEnumerable> in the FluentValidationCommandHandlerDecorator decorator instead of one single IValidator instance. In that case I don't need a NullValidator at all and an empty collection gets injected if no validator is available for the specific command or query.

            SimpleInjector must be changed to register a collection of IValidator instances:



            static field variable initializer FAILS in online compiler but works in VS
            Asked 2021-Jul-25 at 16:57

            I would like to get some clarification in regards to how loose the execution timing is for static field initializers in .NET. I'm getting a TypeInitializationException when running the code below in an online compiler(Fiddle), but I get the expected output of 1 in a test console app in VS.




            Answered 2021-Jul-25 at 08:56

            According to the C# language spec, this is specifically pointed out as an implementation-dependent thing:

            If a static constructor exists in the class, execution of the static field initializers occurs immediately prior to executing that static constructor. Otherwise, the static field initializers are executed at an implementation-dependent time prior to the first use of a static field of that class.

            The only guarantee you get, is that it must be some time before the first use of a static field.

            However, as you probably have found out in your fiddle, adding a static constructor makes this work. A static constructor guarantees that static field initialisers to be run immediately before the static constructor. The good news is that the execution of the static constructor is not implementation-dependent (spec):

            The execution of a static constructor is triggered by the first of the following events to occur within an application domain:

            • An instance of the class type is created.
            • Any of the static members of the class type are referenced.



            Azure Function throws SimpleInjector.ActivationException in "stress test"
            Asked 2021-Jul-12 at 14:47

            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.ActivationException's for about 50% of the time. Not all requests are failing.

            I don't get why this is only for a part of the requests.

            Call stack:

            2021-07-06T08:43:41.159 [Error] Er is een probleem opgetreden

            SimpleInjector.ActivationException : The constructor of type GetLocalKeyDataByDateQueryHandler contains the parameter with name 'queryValidator' and type IValidator, but IValidator is not registered. For IValidator to be resolved, it must be registered in the SimpleInjector.Container.ThrowParameterTypeMustBeRegistered(InjectionTargetInfo target)at SimpleInjector.Advanced.DefaultDependencyInjectionBehavior.GetInstanceProducer(InjectionConsumerInfo dependency,Boolean throwOnFailure)at SimpleInjector.ContainerOptions.GetInstanceProducerFor(InjectionConsumerInfo consumer)at SimpleInjector.Registration.BuildConstructorParameters(ConstructorInfo constructor)at SimpleInjector.Registration.BuildNewExpression()at SimpleInjector.Registration.BuildTransientExpression()at SimpleInjector.Registration.BuildTransientDelegate()at SimpleInjector.Lifestyles.ScopedRegistration.BuildExpression()at SimpleInjector.InstanceProducer.BuildExpressionInternal()at SimpleInjector.Internals.LazyEx`1.InitializeAndReturn()at SimpleInjector.InstanceProducer.BuildInstanceCreator()at SimpleInjector.InstanceProducer.BuildAndReplaceInstanceCreatorAndCreateFirstInstance()at SimpleInjector.InstanceProducer.GetInstance()at SimpleInjector.Container.GetInstanceTServiceat async ProRail.PUIC2.Web.Functions.GetPuicDataByChangeDate.Run(GetPuicDataByDate inputParams,ILogger logger,ExecutionContext context) at D:\a\1\s\Src\Web\ProRail.PUIC2.Web.Functions\Functions\GetPuicDataByChangeDate.cs : 35




            Answered 2021-Jul-12 at 14:47

            It seems there is a multi-threading issue with your code; the DependencyInjection.GetContainerInstance method.

            GetContainerInstance possibly creates many Container instances when called in parallel and the configuration of the final Container instance will be undetermined.

            To fix this issue, you will have to synchronize the creation of the container. There are many ways to do this, but you can, for instance, try this:



            HttpClientFactory with default Polly policy handler registration and injection with SimpleInjector
            Asked 2021-Jun-24 at 08:45


            Answered 2021-Jun-24 at 08:45

            I'm not sure I can give you a satisfying answer, but here's an idea for a possible implementation. You can make the IPollyHttpClientFactory conditional, in a way that each consumer gets its own version. This can be done using the RegisterConditional method. For instance:



            Accessing AppConfig settings via Injection
            Asked 2021-Jun-08 at 22:58

            I have values in my AppConfig like this...



            Answered 2021-Jun-08 at 21:39

            You register type AppConfig as singleton implementation of type IAppConfig, so when you request IAppConfig from container, you'll get an instance created by container, and not 'appConfig' you created in Start. You need to register instance like:



            Simple Injector throws an error in Caliburn.Micro Bootstrapper.Buildup when calling async method in the viewmodel
            Asked 2021-May-14 at 21:51

            I am trying to use Simple Injector as the DI container for Caliburn.Micro. Demo source:

            This project has a basic Caliburn.Micro setup with a Simple Injector Container. The ShellView has 1 button and when pressed, an async method is called to get some simulated data.

            I am getting this error in Bootstrapper.Buildup.

            SimpleInjector.ActivationException: 'No registration for type SequentialResult could be found. Make sure SequentialResult is registered, for instance by calling 'Container.Register();' during the registration phase. An implicit registration could not be made because Container.Options.ResolveUnregisteredConcreteTypes is set to 'false', which is now the default setting in v5. This disallows the container to construct this unregistered concrete type. For more information on why resolving unregistered concrete types is now disallowed by default, and what possible fixes you can apply, see '

            It has been suggested here that commenting out Bootstrapper.BuildUp should work: Caliburn.Micro Bootstrapper 'BuildUp' method throws exception when Simple Injector is used

            However, when doing so, SimpleInjector will still throw an exception.

            Any help solving this would be greatly appreciated

            My complete Bootstrapper config file looks like this:



            Answered 2021-May-14 at 21:51

            @Steven: Commenting out BuildUp indeed fixed my problem.

            I thought that I had tested commenting out BuildUp in my sample project before coming to SO to ask my question, but trying it again now solved my problem. Thank you for putting me back on the right track!

            Solution: comment out / delete BootStrapper.BuildUp as was also suggested here: Caliburn.Micro Bootstrapper 'BuildUp' method throws exception when Simple Injector is used


            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install SimpleInjector

            The easiest way to get started is by installing [the available NuGet packages]( Take a look at the [Using]( section in the documentation on learning how to configure and use Simple Injector. Go to the [Integration]( page to find out how to integrate Simple Injector in your favorate application framework. Look at the [More Information]( section to learn more or if you have any questions.


            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries

            Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Reuse Pre-built Kits with SimpleInjector

            Consider Popular Dependency Injection Libraries


            by golang


            by google


            by inversify


            by square


            by google

            Try Top Libraries by simpleinjector


            by simpleinjectorHTML


            by simpleinjectorHTML


            by simpleinjectorCSS


            by simpleinjectorC#