simple-injector

Simple Injector usage for generic command handler

旧街凉风 提交于 2019-12-20 23:24:07
问题 The interfaces,commands and command handler set up as per instructions in Simpleinjector wiki. public interface ICommand { string Name { get; set; } } public class Command1 : ICommand { public string Name { get; set; } } public class Command2 : ICommand { public string Name { get; set; } } public interface ICommandHandler<TCommand> { void Execute(TCommand Command); } public class Command1Handler : ICommandHandler<Command1> { public void Execute(Command1 Command) { Console.WriteLine(Command

Implementing Domain Event Handler pattern in C# with Simple Injector

╄→尐↘猪︶ㄣ 提交于 2019-12-20 09:46:01
问题 I am trying to implement the Domain Event pattern in C# using Simple Injector. I have simplified my code to be in one file that can be ran as a console app and have excluded the Simple Injector code to keep things clear for the purpose of this question. The problem I am coming up against is that each event could have multiple event handlers and multiple events could be raised but I want to restrict my Dispatcher to only handle events that implement the IEvent interface so I put that restraint

ASP.NET API DI (Simple Injector) null reference on IIS pool recycle

别来无恙 提交于 2019-12-20 04:13:17
问题 I previously posted another question, but after some observations, I have narrowed down to what it may be that's causing my problem. Basically, once the IIS Application Pool is recycled, my dependency injection (which ends up scanning for some DLLs through creating an NWatchApplication), fails. INWatchApplication is a dependency for the Web API project. Here are the contents of the Global.asax: protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration

Registering decorators with primitive configuration dependencies in Simple Injector

南楼画角 提交于 2019-12-20 02:32:55
问题 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

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

情到浓时终转凉″ 提交于 2019-12-19 09:57:09
问题 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

Wiring up Simple Injector in WebForms in .NET 4.7.2

戏子无情 提交于 2019-12-19 07:09:21
问题 With the changes in .NET 4.7.2, constructor injection is now possible in Web Forms. I have gotten Simple Injector working with Web Forms, but would like some input as to if there any "gotchas" I might be missing. First I have the registration of the Pages themselves which is taken from here. public static void RegisterWebPages(this Container container) { var pageTypes = from assembly in BuildManager.GetReferencedAssemblies().Cast<Assembly>() where !assembly.IsDynamic where !assembly

Simpleinjector: Is this the right way to RegisterManyForOpenGeneric when I have 2 implementations and want to pick one?

爱⌒轻易说出口 提交于 2019-12-18 17:26:16
问题 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 that executes synchronously: public class SendEmailMessageHandler : IHandleCommands<SendEmailMessageCommand> { public SendEmailMessageHandler(IProcessQueries queryProcessor , ISendMail mailSender , ICommandEntities entities , IUnitOfWork unitOfWork , ILogExceptions exceptionLogger) { // save

Simple Injector: how to inject HttpContext?

谁说胖子不能爱 提交于 2019-12-18 13:20:11
问题 I have started using Simple Injector as my DI container (mostly for performance reason: if somebody has suggestions, please let me know) but some of the classes I wrote use HttpContextBase as constructor parameter. I have resolved for now removing it from the constructor and creating a Property, something like this: public HttpContextBase HttpContext { get { if (null == _httpContext) _httpContext = new HttpContextWrapper(System.Web.HttpContext.Current); return _httpContext; } set {

How to use WPF controls with Simple Injector dependencies

青春壹個敷衍的年華 提交于 2019-12-18 08:26:52
问题 I'd like to use Dependency Injection in a scenario where I have to inject resources into GUI-controls. As that might be the wrong Place, I have some reasons to do it here and not in a view model (eg. I need Window handles and such). Constructor parameter injection seems to be the preferred way. As most of you know WPF controls must have a parameter-less constructors, otherwise the XAML does not work and for the current scenario I love to keep my XAML since it contains some name registrations

Using Simple Injector with Castle Proxy Interceptor

柔情痞子 提交于 2019-12-18 02:47:49
问题 I'm using Simple Injector in my asp.net mvc 4 project. I can't figure out how can I use Simple Injector with castle proxy interceptor. 回答1: There's in fact a section about Interception in the Simple Injector documentation that pretty clearly describes how to do interception. The code samples given there don't show how to work with Castle DynamicProxy, but you actually need to change a few lines of code to get this working. If you use the Interception Extensions code snippet, to get it working