ioc-container

Typical IoC container usage - passing data down the line

寵の児 提交于 2019-12-30 07:00:08
问题 I've recently started using an IoC container for the first time, but I'm not educated on the best practices for using it. More specificaly I'm using Unity in a C# .NET project, and I started using it because it came with Prism. I use the container to resolve the "top level" objects, and they get the correct objects injected based on the container. However, I can't see the best practice clearly when I have an object with children and children's children, and I need some data from the IoC

IoC - Multiple implementations support for a single interface

非 Y 不嫁゛ 提交于 2019-12-30 01:51:06
问题 I am wondering why .Net IoC containers do not easily support multiple implementations for a single interface! May be I am wrong, but as far I have seen, frameworks like Ninject partially supports this feature using annotations (how?). I do not think other frameworks like Windsor or simple injector have an easy mechanism to support this scenario. Is there any reason why this is not supported by many frameworks? AFAIK, one of the most important reasons to use interfaces is to achieve loose

Castle Windsor intercept method call from within the class

社会主义新天地 提交于 2019-12-29 06:31:52
问题 We have components registrations in Castle Windsor container like so void RegisterComponent<TInterface, TImplementation>() { var component = Component.For<TInterface>().ImplementedBy<TImplementation>(); component.Interceptors<SomeInterceptor>(); container.Register(component); } However we got to the problem that when we do a method call from within the class it does not get intercepted. For example we have component like ServiceA : IService { public void MethodA1() { // do some stuff } public

Are primitive constructor parameters a bad idea when using an IoC Container? [closed]

故事扮演 提交于 2019-12-28 12:46:53
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . Standard newbie disclaimer: I'm new to IoC and am getting mixed signals. I'm looking for some guidance on the following situation please. Suppose I have the following interface and implementation: public interface IImageFileGenerator { void RenameFiles(); void CopyFiles(); }

How to build a graph of resolved instances with Autofac?

家住魔仙堡 提交于 2019-12-25 03:27:19
问题 After all registrations, I am doing ContainerBuilder.RegisterCallback and subscribing to all IComponentRegistration.Preparing and IComponentRegistration.Activating events to be able to handle all activations. With this two events I am able to build a tree, the order of events looks like this: Preparing: Root Preparing: FirstLevel_A Activating: FirstLevel_A Preparing: FirstLevel_B Preparing: SecondLevel_C Activating: SecondLevel_C Activating: FirstLevel_B Activating: Root But what if some

SimpleServiceLocator: Why is automatic constructor injection not supported for singletons?

拜拜、爱过 提交于 2019-12-24 16:58:04
问题 I've been experimenting with the SimpleServiceLocator, and I like it quite a bit, but there's one thing that I'm really frustrated by--you can't use automatic constructor injection for singletons. To make matters worse, you can't even use automatic constructor injection for its dependencies . You have to create the singleton object, all it's dependencies, all its dependencies dependencies, etc. manually. Why is SimpleServiceLocator designed this way? Aren't singletons supposed to be just like

Using Ninject to inject dependencies into externally constructed objects (user control)

◇◆丶佛笑我妖孽 提交于 2019-12-24 13:32:24
问题 I would like to use Ninject in my WinForms application. I cannot figure out how to use it for my user controls. Sometimes they rely on the services I want to configure through the DI framework. These controls need to be manageable through the designer (thus need default constructors). So, is there a way to inject dependencies into properties of this user control? Since the designer needs to be able to construct it, kernel.Get<TestClass> won't work here. Is there a method or some code that

Overriding IOC Registration for use with Integration Testing

前提是你 提交于 2019-12-24 10:27:56
问题 so I think I'm perhaps not fully understanding how you would use an IOC container for doing Integration tests. Let's assume I have a couple of classes: public class EmailComposer : IComposer { public EmailComposer(IEmailFormatter formatter) { ... } ... public string Write(string message) { ... return _formatter.Format(message); } } OK so for use during the real application (I'm using autofac here) I'd create a module and do something like: protected override void Load(ContainerBuilder

How to avoid Cyclic Dependencies when using Dependency Injection?

我们两清 提交于 2019-12-24 06:13:26
问题 I am relatively new to the concept dependency injection, so I am unsure about how it prevents cyclic dependencies. Let's say I have followed projects (the sample project structure might not be good but please bear with me) Project A: Domain Layer IRepository Project B: RepositoryImpl --> implement IRepository interface In this case Project B will need to reference Project A. But to set up Project A, let's say Unity Container, Project A will need to reference Project B in order to have

Castle Windsor Map Named Component To Specific Property

前提是你 提交于 2019-12-24 05:03:07
问题 Following scenario: We use the Fluent API to register all components in an assembly and two components tyepof(A) with named keys. Another class B with two properties typeof(A) should get the named components injected. Sample: public class A : IA {} public class B : IB { [Named("first")] public IA First { get; set; } [Named("second")] public IA Second { get; set; } } // ... container.Register(Component.For<IA>().Instance(new A(value1)).Named("first")); container.Register(Component.For<IA>()