inversion-of-control

How to register Windows Forms with Simple Injector

筅森魡賤 提交于 2019-12-17 07:39:20
问题 Background I'm building a winforms application where I am using an IoC container (SimpleInjector) to register my types. In my application, a majority of the screens (i.e. forms) will only have one instance at any given time. Problem For forms that only need one instance at any given time, I can register them as singletons: container.Register<IHomeView, HomeView>(Lifestyle.Singleton); This allows me to use the container to keep track of all forms. In this case, however, when a form gets closed

Understanding IoC Containers and Dependency Injection

爷,独闯天下 提交于 2019-12-17 06:22:02
问题 My understanding: A dependency is when an instance of ClassA requires an instance of ClassB to instantiate a new instance of ClassA. A dependency injection is when ClassA is passed an instance of ClassB, either through a parameter in ClassA's constructor or through a set~DependencyNameHere~(~DependencyNameHere~ $param) function. (This is one of the areas I'm not completely certain on) . An IoC container is a singleton Class(can only have 1 instance instantiated at any given time) where the

Do I need dependency injection in NodeJS, or how to deal with …?

荒凉一梦 提交于 2019-12-17 06:20:17
问题 I currently creating some experimental projects with nodejs. I have programmed a lot Java EE web applications with Spring and appreciated the ease of dependency injection there. Now I am curious: How do I do dependency injection with node? Or: Do I even need it? Is there a replacing concept, because the programming style is different? I am talking about simple things, like sharing a database connection object, so far, but I have not found a solution that satisfies me. 回答1: In short, you don't

How to explain dependency injection to a 5-year-old? [closed]

核能气质少年 提交于 2019-12-17 03:44:13
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Locked . This question and its answers are locked because the question is off-topic but has historical significance. It is not

Having AutoMapper to inject dependencies using an IoC Container when needed

陌路散爱 提交于 2019-12-14 04:07:17
问题 I have tried almost everything, but I cannot get AutoMapper to map A => B when B doesn't have a parameterless constructor . I'm using Unity and all the dependencies are registered conveniently but, how do I say to AutoMapper "hey, if the target instance needs some dependency in the constructor, ask Unity to build it, and do the mapping later. I've tried with Mapper.Initialize(configuration => { configuration.ConstructServicesUsing(container.Resolve); configuration.CreateMap<Person,

StructureMap resolve dependency through injection instead of service location

大城市里の小女人 提交于 2019-12-14 03:39:42
问题 In my project I register many ISerializers implementations with the assembly scanner. FWIW this is the code that registers my ISerializers Scan(scanner => { scanner.AssemblyContainingType<ISerializer>(); scanner.AddAllTypesOf<ISerializer>().NameBy(type => type.Name); scanner.WithDefaultConventions(); }); Which then correctly registers ISerializer (...ISerializer) Scoped as: Transient JsonSerializer Configured Instance of ...JsonSerializer BsonSerializer Configured Instance of ..

Unit Testing the IoC container itself

这一生的挚爱 提交于 2019-12-14 02:18:49
问题 I don't think this was asked before, although it's really hard to search for a term like unit test ioc container and not find a question about how to implement IoC in order to perform unit tests. I would like to have unit tests against the IoC container itself basically because sometimes I have issues with the container (like you could with any other part of an application), and it's pretty troublesome to test the resolution of dependencies merely debugging. If I could introduce unit tests

java: Spring: How to transfer beans from one ClassPathXMLApplicationContext to another?

巧了我就是萌 提交于 2019-12-14 02:16:27
问题 How to transfer beans from one ClassPathXMLApplicationContext to another? I create one context like this ClassPathXMLApplicationContext myOneContext = new ClassPathXMLApplicationContext("path to my xml bean definitions"); // It loads 10 beans which probably refer each other ClassPathXMLApplicationContext my2ndContext = new ClassPathXMLApplicationContext("path to my xml bean definitions"); // It loads 2 beans, which probably refer each other is it possible to transfer all beans from

Conditional dependency resolution in ASP.NET MVC using castle windsor

99封情书 提交于 2019-12-13 19:38:12
问题 I am trying to solve this case in our code where I need to resolve the dependency at runtime based on a specific condition, such as if certain query string value exist or not. Let say I have a controller AuthenticationController and I have authentication service having two flavours of it. public class AuthenticationController { private readonly IAuthenticationService authenticationService; public AuthenticationController(IAuthenticationService authenticationService) { this

Retrofit unit tests to large solution, IOC, Moq

半世苍凉 提交于 2019-12-13 19:23:23
问题 I am in the process of retrofitting unit tests for a asp.net solution written in VB.Net and c#. The unit tests need to verify the current functionality and act as a check for future breaking changes. The solution comprises of: 1 MVC web project written in vb.net (don't ask, it's a legacy thing) 10 other supporting projects each containing logically grouped functionality written in C#, each project contains repositories and DAL All the classes are tightly coupled as there is no inversion of