dependency-injection

Dependency injection, composition root, and entry points

坚强是说给别人听的谎言 提交于 2020-02-04 03:50:28
问题 I've spent a lot of time reading these articles (along with many others): Mark Seemann - Pure DI Mark Seemann - When to use a DI Container Mark Seemann - Compose object graphs with confidence Mark Seemann - Don't call the container; it'll call you Mark Seemann - Understanding the Composition Root and I'm still trying to wrap my head around DI and the concept of "wiring up the dependencies" and the "auto wiring" functionality of an IoC container. I think I understand the theory of Dependency

Would like Autofac to not register any interface that has more than one implementation

别说谁变了你拦得住时间么 提交于 2020-02-03 10:10:33
问题 I'm currently testing Autofac for our company. We'd like to have the following rules: If an interface has been implemented only once, then add it automatically using the builder.RegisterAssemblyTypes (see below). Otherwise, we need to make sure to manually write the rule that will decide which implementation is the 'default' implementation. I have the following code: var builder = new ContainerBuilder(); builder.RegisterAssemblyTypes(Assembly .Load("Lunch.Service")).As(t => t.GetInterfaces()

Would like Autofac to not register any interface that has more than one implementation

偶尔善良 提交于 2020-02-03 10:10:27
问题 I'm currently testing Autofac for our company. We'd like to have the following rules: If an interface has been implemented only once, then add it automatically using the builder.RegisterAssemblyTypes (see below). Otherwise, we need to make sure to manually write the rule that will decide which implementation is the 'default' implementation. I have the following code: var builder = new ContainerBuilder(); builder.RegisterAssemblyTypes(Assembly .Load("Lunch.Service")).As(t => t.GetInterfaces()

Is @javax.annotation.ManagedBean a CDI bean defining annotation?

前提是你 提交于 2020-02-03 04:59:04
问题 The Question Given that the archive we deploy is an "implicit bean archive" (see below), using @javax.inject.Inject to inject a @javax.annotation.ManagedBean into another managed bean work in WildFly 8.1.0, but it won't work in GlassFish 4.0.1-b08 nor GlassFish 4.1-b13. GlassFish crash with this message: WELD-001408: Unsatisfied dependencies for type... Do I misunderstand the following outlined specifications or do GlassFish have a bug? CDI 1.1 Part 1 CDI 1.1 (JSR-346) section 12.1 "Bean

Swinject - Ambiguous reference to member

☆樱花仙子☆ 提交于 2020-02-02 05:36:06
问题 I am using Swinject in my Swift 3 app. When I tried let container = Container() container.register(NetworkModeling.self) { _ in Network() } I get an error saying Ambiguous reference to member 'register(_:name:factory:)' What is wrong here? 回答1: I faced the same issue and i think compiler could be a bit more verbose in this case. Anyway, my problem was on my side, not in Swinject Check the following: NetworkModeling and Network are visible in scope of your registration (they are public , or

Simple Injector: Injecting a property in a base class

百般思念 提交于 2020-02-01 05:31:25
问题 For several weeks I've been using the Simple Injector dependency injection container, with great success. I love the easy by which I can configure it. But now I have a design that I don't know how to configure. I have a base class where many types from derive, and I want to inject a dependency into a property of the base class, but without having to configure that for every derived class. I tried to do this with attributes, but Simple Injector does not support attributes. Here is a trimmed

ASP.NET Core Singleton instance vs Transient instance performance

时间秒杀一切 提交于 2020-02-01 02:17:52
问题 In ASP.NET Core Dependency Injection, I just wonder if registering Singleton instances will improve performance better than registering Transient instances or not? In my thinking, for Singleton instance, it just cost once time for creating new object and dependent objects. For Transient instance, this cost will be repeat for each service request. So Singleton seems to be better. But how much performance gaining we have when using Singleton over Transient ? Thank you in advanced! 回答1: Like

ASP.NET Core Singleton instance vs Transient instance performance

痞子三分冷 提交于 2020-02-01 02:17:25
问题 In ASP.NET Core Dependency Injection, I just wonder if registering Singleton instances will improve performance better than registering Transient instances or not? In my thinking, for Singleton instance, it just cost once time for creating new object and dependent objects. For Transient instance, this cost will be repeat for each service request. So Singleton seems to be better. But how much performance gaining we have when using Singleton over Transient ? Thank you in advanced! 回答1: Like

Registering a type with multiple constructors and string dependency in Simple Injector

断了今生、忘了曾经 提交于 2020-02-01 00:37:36
问题 I'm trying to figure out how to use Simple Injector, I've used it around the project with no problems registering simple services and their components. However, I wanted to use dependency injector when having a component with more than two constructors that implements an interface. public DAL: IDAL { private Logger logger; string _dbInstance; public DAL() { logger = new Logger(); } public DAL(string databaseInstance) { logger = new Logger(); _dbInstance = databaseInstance; } } Here is how I'm

Dagger 2 Singleton Component Depend On Singleton

断了今生、忘了曾经 提交于 2020-02-01 00:13:31
问题 I've got a strange problem here, and I'm not quite sure why what I'm doing isn't allowed. I've got the following modules: @Module public final class AppModule { private Context mContext; @Provides @Singleton @AppContext public Context provideContext() { return mContext; } } @Module public final class NetModule { @Provides @Singleton public OkHttpClient provideOkHttp() { return new OkHttpClient.Builder().build(); } } For various reasons, I don't want to have these two modules in the same