inversion-of-control

laravel - dependency injection and the IoC Container

南楼画角 提交于 2019-12-30 02:28:09
问题 I'm trying to wrap my head around dependency injection and the IoC container and i'm using my UserController as an example. I'm defining what the UserController depends on in its constructor and then am binding those objects to it using App::bind(). If i'm using the Input::get() facade/method/thing am i not taking advantage of the Request object i just injected into it? Should i be using the following code instead, now that the Request object is injected or doesInput::get() resolve to the

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

Multiple Interface injection with castle windsor

瘦欲@ 提交于 2019-12-30 00:39:10
问题 How can you get castle Windsor to choose the right implantation of a interface at run time when you have multiple implementations in the container. For example lets say i have a simple interface called IExamCalc that does calculations to work out how someone did in that exam. No we have several implementation of this like bellow for example, public interface IExamCalc { int CalculateMark(ExamAnswers examAnswers) } public class WritenExam : IExamCalc { public int CalculateMark(ExamAnswers

Angular 2 Injectable Interface?

房东的猫 提交于 2019-12-29 01:42:11
问题 Today I stumbled upon something that I didn't think would cause me trouble. In Java and Spring, I can declare two beans that both implement a given interface, while in another class where they are injected I only work with the interface; this is in fact what I love with IoC: you don't really have to know what object you're working with, only it's kind . So in my little Angular2/Typescript program, I was trying to do the same: webapp.module.ts: ... import { WebAppConfigurationService } from '.

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(); }

What should I consider when choosing a dependency injection framework for .NET

倖福魔咒の 提交于 2019-12-28 09:47:00
问题 see also Which C#/.NET Dependency Injection frameworks are worth looking into? There are now many dependency injection frameworks to choose from. You used to often be forced to use a given dependency injection framework due to a library you were using. However the Common Service Locator library has enabled library code to be independent of injection frameworks. The time it takes to learn all of them well enough to decide which to use is unreasonable. I don’t believe that we have yet reached a

IoC / Dependency Injection - please explain code versus XML

假如想象 提交于 2019-12-28 01:35:08
问题 I understand basically how IoC frameworks work, however one thing I don't quite get is how code-based config is supposed to work. With XML I understand how you could add a new assembly to a deployed application, then change the config in XML to include it. If the application is already deployed (i.e., compiled in some form) then how can code changes be made without recompiling? Or is that what people do, just change config in code and recompile? 回答1: Hot-swapping dependencies is not the only

How to remove unit of work functionality from repositories using IOC

只愿长相守 提交于 2019-12-27 14:01:47
问题 I have an application using ASP.NET MVC, Unity, and Linq to SQL. The unity container registers the type AcmeDataContext which inherits from System.Data.Linq.DataContext , with a LifetimeManager using HttpContext . There is a controller factory which gets the controller instances using the unity container. I set-up all my dependencies on the constructors, like this: // Initialize a new instance of the EmployeeController class public EmployeeController(IEmployeeService service) // Initializes a

How to remove unit of work functionality from repositories using IOC

天涯浪子 提交于 2019-12-27 13:58:54
问题 I have an application using ASP.NET MVC, Unity, and Linq to SQL. The unity container registers the type AcmeDataContext which inherits from System.Data.Linq.DataContext , with a LifetimeManager using HttpContext . There is a controller factory which gets the controller instances using the unity container. I set-up all my dependencies on the constructors, like this: // Initialize a new instance of the EmployeeController class public EmployeeController(IEmployeeService service) // Initializes a

Tapestry IoC constructor and injection

会有一股神秘感。 提交于 2019-12-25 14:46:45
问题 I have the following class: public class MyClass { @Inject private MyAnotherClass myAnotherClass; public MyClass() { //Perform operations on myAnotherClass. } } I need to do some things in constructor which require an instance of myAnotherClass . Unfortunately myAnotherClass is injected after code in constructor is ran, which means I am performing operations on null ... I could of course instantiate it the classic way ( MyAnotherClass myAnotherClass = new MyAnotherClass() ) directly in