simple-injector

Lifestyle errors for DbContexts with multiple injections (ex. EntityRepository<TEntity> and FooService)

♀尐吖头ヾ 提交于 2019-12-25 08:02:15
问题 I apologize for the lengthy post. Feel free to skip to Question at the bottom. The context is an ASP.NET system. Its data layer is based on Entity Framework, and dependency injection is facilitated by Simple Injector. There is currently only one DbContext and it is consumed by multiple classes in a command/query-like business services layer as well as basic repositories. Before // Context self mapped container.Register<SomeContext>(Lifestyle.Scoped); // Repositories were individually mapped,

Resolve instances by key and auto-registration with SimpleInjector

微笑、不失礼 提交于 2019-12-24 07:48:28
问题 I'm trying to resolve instances by key with SimpleInjector. In my case, the keys are strings which are coming from a configuration file, and I need the factory to return the correct type based on the string. I used a similar solution like the one described in the link above, but changed it slightly, so the instances can provide their own keys. (there will be many classes that implement IFoo , so I'd like to auto-register them with their keys) Here is the complete working example (.NET Core

Resolve instances by key and auto-registration with SimpleInjector

牧云@^-^@ 提交于 2019-12-24 07:48:25
问题 I'm trying to resolve instances by key with SimpleInjector. In my case, the keys are strings which are coming from a configuration file, and I need the factory to return the correct type based on the string. I used a similar solution like the one described in the link above, but changed it slightly, so the instances can provide their own keys. (there will be many classes that implement IFoo , so I'd like to auto-register them with their keys) Here is the complete working example (.NET Core

container.RegisterWebApiControllers(GlobalConfiguration.Configuration) causes InvalidOperationException

微笑、不失礼 提交于 2019-12-23 09:04:02
问题 In my integration tests I'm using the same SimpleInjector.Container which I construct in the Web API project I'm testing. But this line in composition root class: container.RegisterWebApiControllers(GlobalConfiguration.Configuration); causes an exception: System.TypeInitializationException : The type initializer for 'MyProject.Api.Test.Integration.HttpClientFactory' threw an exception. ---- System.InvalidOperationException : This method cannot be called during the application's pre-start

using simple injector in mvc6 with cookie auth

蓝咒 提交于 2019-12-23 05:51:52
问题 I have a MVC6 project using simple injector and cookie middleware for authentication without ASP.NET identity (tutorials below) http://simpleinjector.readthedocs.org/en/latest/aspnetintegration.html http://docs.asp.net/en/latest/security/authentication/cookie.html I have a custom SignInManager / UserManager that wraps PrincipalContext to validate windows credentials (SideNote: I am not using the Azure AD with aspnet 5 because [in the future] I know there will be a mix of windows and non

“An MVC filter provider has already been registered for a different Container instance.” in Simple Injector 2.6

独自空忆成欢 提交于 2019-12-22 08:57:10
问题 I previously had the setup for property injection in one of my attributes as Container.RegisterInitializer<PermitAttribute>(initialize => { initialize.QueryProcessor = Container.GetInstance<IQueryProcessor>(); }); And the usage was public class PermitAttribute : ActionFilterAttribute { public IQueryProcessor QueryProcessor { get; set; } } but after updating to simpleinjector 2.6.1 The property injection broke. When I am trying to access QueryProcessor object inside PermitAttribute. It

Simple Injector and default AccountContoller dependency issue

点点圈 提交于 2019-12-22 08:49:58
问题 I have problem with Simple Injector in my Web Api project. I user default AccountController generated by VS. public AccountController(ApplicationUserManager userManager, ISecureDataFormat<AuthenticationTicket> accessTokenFormat) In my configuration file I register: var container = new Container(); // This is an extension method from the integration package. container.RegisterWebApiFilterProvider(config); container.RegisterWebApiControllers(config); container.Register<IInitializeService,

SimpleInjector mixed lifestyle for per web request and lifetime scope

我的未来我决定 提交于 2019-12-22 08:01:07
问题 I am using Simple Injector as my IoC container and employ the following technique to enable registering a "mixed" lifestyle for some objects as both per web request or per thread. interface IUnitOfWork { } interface IWebUnitOfWork : IUnitOfWork { } interface IThreadUnitOfWork : IUnitOfWork { } class UnitOfWork : IWebUnitOfWork, IThreadUnitOfWork { } container.RegisterPerWebRequest<IWebUnitOfWork, UnitOfWork>(); container.RegisterLifetimeScope<IThreadUnitOfWork, UnitOfWork>(); container

Does SimpleInjector's WebAPIRequest lifetime include Message Handlers?

≯℡__Kan透↙ 提交于 2019-12-21 20:29:30
问题 I'm new to SimpleInjector and working through examples using it with WebAPI. I used the SimpleInjector.Integration.WebApi.WebHost.QuickStart nu-get package, then registered a simple type for my tests, like so: container.RegisterWebApiRequest<SimplePOCO>(); From inside an ApiController method, I am able to request an instance. So far, so good. I wanted to expand my test to earlier in pipeline, specifically a Message Handler. So I created a simple DelegatingHandler like : protected override

SimpleInjector and FluentValidationFactory

核能气质少年 提交于 2019-12-21 05:13:12
问题 I am trying to automate the validation of my view models, I know I can just add a an attribute to specify my validation but there is an option to set up a factory to automate all that, I looked at: this answer and came up with this using simple injector 3.1: public class CustomValidatorFactory:ValidatorFactoryBase { private readonly Container siContainer; public CustomValidatorFactory(Container siContainer) { var assemblies = AppDomain.CurrentDomain.GetAssemblies().ToList(); this.siContainer