What is Castle Windsor, and why should I care?

I’m a long-time Windows developer, having cut my teeth on win32 and early COM. I’ve been working with .NET since 2001, so I’m pretty fluent in C# and the CLR. I’d never heard of Castle Windsor until I started participating in Stack Overflow. I’ve read the Castle Windsor “Getting Started” guide, but it’s not clicking. … Read more

.NET Core DI, ways of passing parameters to constructor

Having the following service constructor public class Service : IService { public Service(IOtherService service1, IAnotherOne service2, string arg) { } } What are the choices of passing the parameters using .NET Core IOC mechanism services.AddSingleton<IOtherService , OtherService>(); services.AddSingleton<IAnotherOne , AnotherOne>(); services.AddSingleton<IService>(x => new Service( services.BuildServiceProvider().GetService<IOtherService>(), services.BuildServiceProvider().GetService<IAnotherOne >(), “”)); Is there any other way ? 4 … Read more

InvalidOperationException: Unable to resolve service for type ‘Microsoft.AspNetCore.Http.IHttpContextAccessor’

I started to convert my asp.net core RC1 project to RC2 and faced with problem that now IHttpContextAccessordoes not resolved. For sake of simplicity I created new ASP.NET RC2 project using Visual Studio Template ASP.NET Core Web Application (.Net Framework). Than I added constructor for HomeController which template created for me. public HomeController(IHttpContextAccessor accessor) { … Read more

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

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 … Read more

Passing Parameters JavaFX FXML

How can I pass parameters to a secondary window in javafx? Is there a way to communicate with the corresponding controller? For example: The user chooses a customer from a TableView and a new window is opened, showing the customer’s info. Stage newStage = new Stage(); try { AnchorPane page = (AnchorPane) FXMLLoader.load(HectorGestion.class.getResource(fxmlResource)); Scene scene … Read more

Dependency Inject (DI) “friendly” library

I’m pondering the design of a C# library, that will have several different high level functions. Of course, those high-level functions will be implemented using the SOLID class design principles as much as possible. As such, there will probably be classes intended for consumers to use directly on a regular basis, and “support classes” that … Read more

What exactly is Field Injection and how to avoid it?

I read in some posts about Spring MVC and Portlets that field injection is not recommended. As I understand it, field injection is when you inject a Bean with @Autowired like this: @Component public class MyComponent { @Autowired private Cart cart; } During my research I also read about constructor injection: @Component public class MyComponent … Read more

Spring @Autowire on Properties vs Constructor

So since I’ve been using Spring, if I were to write a service that had dependencies I would do the following: @Component public class SomeService { @Autowired private SomeOtherService someOtherService; } I have now run across code that uses another convention to achieve the same goal @Component public class SomeService { private final SomeOtherService someOtherService; … Read more

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

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 … Read more

Injecting Mockito mocks into a Spring bean

I would like to inject a Mockito mock object into a Spring (3+) bean for the purposes of unit testing with JUnit. My bean dependencies are currently injected by using the @Autowired annotation on private member fields. I have considered using ReflectionTestUtils.setField but the bean instance that I wish to inject is actually a proxy … Read more