dependency-injection

.NET Core DI, register a default implementation for a package

岁酱吖の 提交于 2019-12-24 17:44:09
问题 How can one register a default implementation using the IoC container for .NET Core and also provide a way to override the existing implementation ? For example, I might want to create a package which provide a default implementation for some service. namesapce Package { public interface ISomeService { } public class Default : ISomeService { } } This service is then used inside the same package. namesapce Package { public class Service { Service(ISomeService service) { } } } How to register

Integrating multi scope dagger 2 components

纵然是瞬间 提交于 2019-12-24 17:43:36
问题 Preconditions I have the following components: ApplicationCompoennt - With @ApplicationScope - This component contains LogModule. The logmodule @Provides Logger. ActivityComponent with @ActivityScope - This component contains MyActivityModule. Since one can't call the ctor of Activity explicitly, this module is used to inject the activity. This component depends on @ApplicationScope component, to use the Logger. BroadcastComponent with @BroadcastReceiverScope - This component contains

hazelcast not getting MapStore from spring beans (autowired dependency is null)

女生的网名这么多〃 提交于 2019-12-24 17:34:09
问题 I am implementing the hazelcast map store for persistence. But could not autowired spring beans(DataSource below) into the hazelcast mapstore object (meaning hazelcast not getting the map store object from spring beans). I read that hazelcast supports spring DI. What am i missing ? Below is my partial map store code If I get the bean from context using get bean like below MySQLStore store = (MySQLStore)context.getBean(MySQLStore.class); I get mysql store with the datasource dependency

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

What if I want to have my own plug-in architecture within Grails?

拈花ヽ惹草 提交于 2019-12-24 16:57:11
问题 Suppose I want to define an interface, FooProvider, and then have multiple implementations of this interface available at runtime (maybe as individual services). In my controller class, I'd like to be able to have all known implementations of this interface injected at runtime so that I can expose them as "options" to the user for getting different types of "Foo" items. This would allow my server-side code to be a lot more modular and allow multiple people to define different ways of plugging

Spring autowire HttpServletRequest in integration tests

£可爱£侵袭症+ 提交于 2019-12-24 16:40:42
问题 We have singleton controllers like @Controller class C { @Autowire MyObject obj; public void doGet() { // do something with obj } } MyObject is created in a filter/interceptor and is put into HttpServletRequest attributes. Then it's obtained in @Configuration: @Configuration class Config { @Autowire @Bean @Scope("request") MyObject provideMyObject(HttpServletRequest req) { return req.getAttribute("myObj"); } } Everything works well in main code, but not in testing: when I run it from an

How do you add a runtime string parameter into a dependency resolution chain?

泄露秘密 提交于 2019-12-24 16:20:35
问题 How could I setup my chosen DI for this kind of setup: public abstract class BaseRepo { public BaseRepo(string token) { } } public RepoA : BaseRepo, IRepoA { // implementation of interface here } public ViewModelA { IRepoA _repo; public ViewModelA(IRepoA repo) { this._repo = repo; } public DoMethod() { this._repo.DoSomeStuff(); } } In real scenario, the token parameter on the base class is resolved after the user has been logged in. I was thinking of just configuring the interfaces for DI

How to Use Dependency Injection on UserControls & Forms

喜你入骨 提交于 2019-12-24 15:53:30
问题 Running into a knowledge gap, been out of WinForms for so long, unsure if i am doing this correctly for Castle Windsor. For the last 5 years i have developing ASP.Net applications (WebForms, MVC, etc). I now have a project where a web interface is not a viable solution, yet. So we are doing it with WinForms. With Asp.Net, i would have just set up the Castle Windsor Container, CWC , static class and everything would have taken care of itself for Dependency Injections, etc. I am having some

Autofac PerLifetimeScope vs PerRequest in web applications

杀马特。学长 韩版系。学妹 提交于 2019-12-24 15:22:48
问题 Using Autofac DI container- What is the difference between registering a unit of work in my web application as per request to registering it as PerLifetimeScope? Autofac creates a new scope for each request and by registering the unit of work as PerMatchingScope it will anyways be resolved from the scope created for the request. If I'm mistaken, please correct me, otherwise, what is the difference? Moreover, If I register the UoW as PerLifetimeScope, and have a console application that sends

How to wire up AutoFac to Common.Logging?

僤鯓⒐⒋嵵緔 提交于 2019-12-24 15:22:00
问题 I have a class like so: public class LoggedFoo { private readonly ILog _logger; public LoggedFoo(ILog logger) { this._logger = logger; } public DoStuff() { this._logger.Info(i => i("Doing stuff...")); } } One of the business requirements is that logs are being generated for certain functions, so naturally I want to mock out the ILog to verify. However, Common.Logging library supports type-based loggers, along the lines of: var logger = LogManager.GetLogger<LoggedFoo>(); ...or: var logger =