inversion-of-control

When to use an IOC container?

巧了我就是萌 提交于 2019-12-20 10:29:23
问题 I'm trying to understand when I should use a container versus manually injecting dependencies. If I have an application that uses a 1-2 interfaces and only has 1-2 concrete implementations for each interface, I would lean towards just handling that myself. If I have a small application that uses 2-3 interfaces and each interface has 2-3 concrete implementations, should I use a full-blown container? Would something something simple like this suffice? Basically I'm trying to understand when it

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

How does Reflection in Laravel work?

你说的曾经没有我的故事 提交于 2019-12-20 08:19:43
问题 How does reflection in Laravel actually work? I tried to debug it to see how Laravel uses reflection in a controller's constructor or methods to resolve their dependencies and sub-dependencies and then and give it back to us. But I found it hard, and it's very complicated to see and to even understand 50% of. Jumping from class to class, I can't really see it. I tried a few times by debugging it with low results of understanding. I am very impressed by this and by reflection, and the way

Dependency Inversion Principle (SOLID) vs Encapsulation (Pillars of OOP)

家住魔仙堡 提交于 2019-12-20 08:07:03
问题 I was recently having a debate about the Dependency Inversion Principle , Inversion of Control and Dependency Injection . In relation to this topic we were debating whether these principles violate one of the pillars of OOP, namely Encapsulation . My understanding of these things is: The Dependency Inversion Principle implies that objects should depend upon abstractions, not concretions - this is the fundamental principle upon which the Inversion of Control pattern and Dependency Injection

Can't get value of Ninject ConstructorArgument (passed in as parameter to kernel.Get)

旧巷老猫 提交于 2019-12-20 07:19:40
问题 Having trouble getting the value of a ConstructorArgument parameter passed to kernel.Get(). I want to use the parameter's value to determine which of two string values will be passed into the constructor. The parameter is in fact there when expected, I just can't get at its value. I end up with a null ref exception after calling the parameter's GetValue method: namespace MyNS.DBProviders { public abstract class DBProviderBase { private ObjectContext _db; public DBProviderBase(ObjectContext db

Interfaces are annotated with @Component annotation in spring IoC/DI. What could be the reason?

不问归期 提交于 2019-12-20 05:25:35
问题 Some times interfaces are annotated with @Component annotation. Then my obvious reasoning was that classes that implement such interface will be treated as components as well. But if I am right that is not the case. So what is the purpose of @Component annotation on interfaces. 回答1: Annotating an interface with @Component is common for Spring classes, particularly for some Spring stereotype annotations : package org.springframework.stereotype; ... @Component public @interface Service {...} or

Is this possible with Unity (Instead of Castle Windsor)?

本小妞迷上赌 提交于 2019-12-20 04:59:43
问题 This blog post shows a way to implement auto mocking with Castle Windsor and NSubstitute. I don't know or use Castle Windsor, but I do use Unity and NSubstitute. Is there a way to do what he shows using Unity? Here is relevant content of the post: First of all, register an ILazyComponentLoader into Windsor: var c = new WindsorContainer(); c.Register(Component.For<LazyComponentAutoMocker>()); Then, the implementation of LazyComponentAutoMocker is simply this: public class

Ninject Conventions with Ninject Factory Extension To Bind Multiple Types To One Interface

霸气de小男生 提交于 2019-12-20 04:54:10
问题 I'm trying to expand on the scenario asked in the SO question titled Ninject Factory Extension Bind Multiple Concrete Types To One Interface by using Ninject Conventions for convention-based binding of the ICar implementations. I'm working off the accepted answer authored by Akim and his Gist outlining the full example. The difference is that I've replaced the explicit ICar bindings with convention-based bindings (or an attempt at it, at least ;) public class CarModule : NinjectModule {

How do I avoid the service locator pattern? Should I?

倖福魔咒の 提交于 2019-12-20 03:12:52
问题 I'm currently working on a WinForms system (I know) where there's a lot of Constructor Injection when creating forms, but if those forms/views need to open another form, I find the DI container has been injected too so that we can locate the implementation of the desired view interface at runtime. e.g. public partial class MyView : Form, IMyView { private readonly IDIContainer _container; public MyView(IDIContainer container) { InitializeComponent(); _container = container; } public

IOC on IValidationDictionary with Castle Windsor

白昼怎懂夜的黑 提交于 2019-12-20 02:58:26
问题 I'm new to Castle Windsor and am just using the latest version. I've created entries for my repositories which are working fine but I have one final dependency that I'm passing into my controller. I've created a ModelStateWrapper which inherits from IValidationDictionary. The ModelStateWrapper takes a ModelStateDictionary in it's constructor so that in my code I can pass the following as an example: IMembershipService _memSvc; IValidationDictionary _validationService; public AccountController