simple-injector

Simple Injector: Register ILogger<T> by using ILoggerFactory.CreateLogger<T>()

ぐ巨炮叔叔 提交于 2019-12-02 19:33:12
I'm working with a project which utilizes Simple Injector as dependency injector. On the other hand, this project uses Microsoft.Extensions.Logging in order to log the events that occurs in certain classes. My technical issue is pretty simple to explain. I want to register in my DI the ILogger independently of the class T which is being invoked, but I DO NEED to do it from my ILoggerFactory.CreateLogger<T>() method because this gets the logger configuration using Microsoft.Extensions.Configuration . I need to use something like this in order to instance my logger: private Microsoft.Extensions

No registration for type ICommandHandler using SimpleInjector APIv3

我的未来我决定 提交于 2019-12-02 14:08:31
问题 I've been playing around with SimpleInjector and I'm trying to register properly all command handlers. Here is my code: CQRS.cs public interface ICommand {} public interface ICommandDispatcher { void Execute(ICommand command); } public class CommandDispatcher : ICommandDispatcher { private readonly Container container; public CommandDispatcher(Container container) { this.container = container; } public void Execute(ICommand command) { var handlerType = typeof(ICommandHandler<>)

No registration for type ICommandHandler using SimpleInjector APIv3

自作多情 提交于 2019-12-02 03:58:35
I've been playing around with SimpleInjector and I'm trying to register properly all command handlers. Here is my code: CQRS.cs public interface ICommand {} public interface ICommandDispatcher { void Execute(ICommand command); } public class CommandDispatcher : ICommandDispatcher { private readonly Container container; public CommandDispatcher(Container container) { this.container = container; } public void Execute(ICommand command) { var handlerType = typeof(ICommandHandler<>).MakeGenericType(command.GetType()); dynamic handler = container.GetInstance(handlerType); handler.Handle((dynamic

Register subset of Web API controllers with simple injector

佐手、 提交于 2019-12-02 01:59:08
问题 I'm manually registrering a subset of my project's Web API controllers: container.Register(typeof(ILGTWebApiController), controllerType, Lifestyle.Transient); Works fine. However, when I run: GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container); It seems to affect all Web API controllers in the project. I would like to leave the other ones untouched by simple injector. If I don't run the code above, simple injector will complain about my

Registering decorators with primitive configuration dependencies in Simple Injector

心已入冬 提交于 2019-12-01 22:37:22
I have an IAppSettingsLoader interface that abstracts away the file IO for loading my app.config file. public interface IAppSettingsLoader { IEnumerable<KeyValuePair<string, string>> LoadAppSettings(); } I have a class that loads the actual file: public class FileAppSettignsLoader : IAppSettingsLoader { public IEnumerable<KeyValuePair<string, string>> LoadAppSettings() { // Perform actual loading through ConfigurationManager.AppSettings } } Then I have a caching decorator that tries to monitor file changes to app.config public class CachedAppSettingsLoader : IAppSettingsLoader { private

Unable to register Api Controller using Simple Injector?

只愿长相守 提交于 2019-12-01 22:00:28
I have a WebApi that uses Simple Injector that was working perfectly fine, but i had to implement OAuth in to the project. Now i have done that and my ApiControllers give me an error like Simple Injector has now been setup correctly I have my Start.cs file public class Startup { public void Configuration(IAppBuilder app) { // Web API configuration and services HttpConfiguration config = new HttpConfiguration(); Container container = SimpleInjectorConfig.Initialize(app); ConfigureAuth(app, container); WebApiConfig.Register(config); app.UseWebApi(config); } public void ConfigureAuth(IAppBuilder

Register multiple singletons with same interface but different constructor parameters

烈酒焚心 提交于 2019-12-01 11:38:26
I have 2 storage (Azure) accounts lets call them src and dest and I have controllers that require access to both and I'm trying to work out how to register these 2 singletons conditionally. This answer gave me some hope but I can't quite work it out, what I want to do is something like (appreciate RegisterSingletonConditional isn't a valid fn): IBlobAccessClient src = new BlobAccessClient(srcConnectionString); IBlobAccessClient dest = new BlobAccessClient(destConnectionString); container.RegisterSingletonConditional<IBlobAccessClient>( src, c => c.Consumer.Target.Parameter.Name.Contains("src")

Register multiple singletons with same interface but different constructor parameters

时间秒杀一切 提交于 2019-12-01 09:02:47
问题 I have 2 storage (Azure) accounts lets call them src and dest and I have controllers that require access to both and I'm trying to work out how to register these 2 singletons conditionally. This answer gave me some hope but I can't quite work it out, what I want to do is something like (appreciate RegisterSingletonConditional isn't a valid fn): IBlobAccessClient src = new BlobAccessClient(srcConnectionString); IBlobAccessClient dest = new BlobAccessClient(destConnectionString); container

SimpleInjector: Injection does not work with MVC 4 ASP.NET Web API

无人久伴 提交于 2019-12-01 08:45:26
I have this setup: public static void Initialize(ISessionFactory factory) { var container = new Container(); InitializeContainer(container, factory); container.RegisterMvcControllers( Assembly.GetExecutingAssembly()); container.RegisterMvcAttributeFilterProvider(); container.Verify(); DependencyResolver.SetResolver( new SimpleInjectorDependencyResolver(container)); } private static void InitializeContainer( Container container, ISessionFactory factory) { container.RegisterPerWebRequest<ISession>( () => factory.OpenSession(), true); } The Initialize method is called in Application_Start :

Simple Injector Identity UserManager<AppUser, Int32> Registration Error

谁说我不能喝 提交于 2019-12-01 07:03:40
问题 I am following Onion Architecture and using Identity Framework. In my Core project, I have: public interface IUserRepository : IDisposable { // Repository methods....... } In my Architecture.Repository, I have public class UserRepository : IUserRepository { // This is Identity UserManager private readonly UserManager<AppUser, int> _userManager; private readonly IAuthenticationManager _authenticationManager; private bool _disposed; public UserRepository(UserManager<User, int> userManager,