dependency-injection

Dependency injection with unique_ptr to mock

大城市里の小女人 提交于 2019-12-28 17:55:29
问题 I have a class Foo that uses class Bar. Bar is used only in Foo and Foo is managing Bar, therefore I use unique_ptr (not a reference, because I don't need Bar outside of Foo): using namespace std; struct IBar { virtual ~IBar() = default; virtual void DoSth() = 0; }; struct Bar : public IBar { void DoSth() override { cout <<"Bar is doing sth" << endl;}; }; struct Foo { Foo(unique_ptr<IBar> bar) : bar_(std::move(bar)) {} void DoIt() { bar_->DoSth(); } private: unique_ptr<IBar> bar_; }; So far

How to Resolve type based on end-user configuration value?

烈酒焚心 提交于 2019-12-28 17:31:28
问题 I have an interface (call it IAcmeService) that has multiple implementations. FileSystemAcmeService DatabaseAcmeService NetworkAcmeService The end-user needs to be able to select which implementation will be used and also save that selection. Currently I'm configuring my IOC container (Unity) to register all the known implemenatation with a name. container.RegisterType(of IAcmeService, FileSystemAcmeService)("FileSystemAcmeService") container.RegisterType(of IAcmeService, DatabaseAcmeService)

How to Resolve type based on end-user configuration value?

送分小仙女□ 提交于 2019-12-28 17:31:12
问题 I have an interface (call it IAcmeService) that has multiple implementations. FileSystemAcmeService DatabaseAcmeService NetworkAcmeService The end-user needs to be able to select which implementation will be used and also save that selection. Currently I'm configuring my IOC container (Unity) to register all the known implemenatation with a name. container.RegisterType(of IAcmeService, FileSystemAcmeService)("FileSystemAcmeService") container.RegisterType(of IAcmeService, DatabaseAcmeService)

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

Angular 6 providedIn - how to customize the @Injectable() provider for dependency injection?

↘锁芯ラ 提交于 2019-12-28 12:11:54
问题 In Angular 5, if I had AbstractClassService and ExtendedClassService that extends the abstract, I could do this in my NgModule's providers array: @NgModule({ providers: [ {provide: AbstractClassService, useClass: ExtendedClassService} ] }) export class AppModule {} This would allow me to switch ExtendedClassService with another for testing or whatever very easily. This can still be done with Angular 6, however there is the new providedIn option that can be set within the service itself to

Angular 6 providedIn - how to customize the @Injectable() provider for dependency injection?

China☆狼群 提交于 2019-12-28 12:11:21
问题 In Angular 5, if I had AbstractClassService and ExtendedClassService that extends the abstract, I could do this in my NgModule's providers array: @NgModule({ providers: [ {provide: AbstractClassService, useClass: ExtendedClassService} ] }) export class AppModule {} This would allow me to switch ExtendedClassService with another for testing or whatever very easily. This can still be done with Angular 6, however there is the new providedIn option that can be set within the service itself to

Appengine with Google Cloud Endpoints and Guice

*爱你&永不变心* 提交于 2019-12-28 12:04:19
问题 So i want to use Guice in Appengine with Cloud Endpoints to inject my services, or daos - pretty common I guess, but I found no tutorial for this. Official Guice for Appengine documentation seems to be here: https://github.com/google/guice/wiki/GoogleAppEngine When configuring Guice you set up the com.google.inject.servlet.GuiceFilter to intercept every request "/*". And at some point you must initialize the modules. Like the documentation says a good place to do that is a

Does “Avoid dependency injection frameworks” in the Android Memory Guide apply to Dagger as well?

孤者浪人 提交于 2019-12-28 11:42:34
问题 So I have come across this best practices on Android articles on memory performance. http://developer.android.com/training/articles/memory.html They said Avoid dependency injection frameworks Using a dependency injection framework such as Guice or RoboGuice may be attractive because they can simplify the code you write and provide an adaptive environment that's useful for testing and other configuration changes. However, these frameworks tend to perform a lot of process initialization by

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

Dependency Injection in HtmlHelper extension method?

人盡茶涼 提交于 2019-12-28 06:28:10
问题 I want to implement property renderers as handlers. I am using Autofac as a DI container in the app. How can I get objects implementing IPropertyHandler in HtmlHelper extension without using globally accessible container (service location)? Is it a way to register own HtmlHelper in Autofac? Maybe MVC framework provide another way? public static class HtmlHelperExtensions { public static MvcHtmlString Editor(this HtmlHelper html, object model) { return new Renderer(new List<IPropertyHandler>()