dependency-injection

How do i get MEF container to inject himself

早过忘川 提交于 2020-01-05 10:33:25
问题 I'm using constructor injection with MEF Composition Container and I want to know how can I make the CompositionContainer inject itself on the instance of the object he is providing. 回答1: You can use one of the CompositionContainer.ComposeExportedValue methods to create a part from a given object. Here's a sample: class Program { static void Main(string[] args) { var container = new CompositionContainer(new ApplicationCatalog()); Console.WriteLine("Main: container [{0}]", container

Hybris OOTB bean is not being injected

为君一笑 提交于 2020-01-05 08:29:11
问题 Debugging , I see that the attribute customPopulators of OOTB class: de.hybris.platform.cmsfacades.cmsitems.converter.DefaultCMSItemConverter Isn't being injected (however the other attributes are being injected) despite of being well configured via XML. <alias name="defaultCMSItemConverter" alias="cmsItemConverter"/> <bean name="defaultCMSItemConverter" parent="baseCMSItemConverter"> <property name="attributeStrategyConverter" ref="cmsAttributeStrategyConverter"/> <property name=

Configuring StructureMap to generate and “remember” a constructor param literal

ぐ巨炮叔叔 提交于 2020-01-05 07:58:28
问题 I have a StructureMap config that looks something like: cfg.For<ICacheOrder>().Use<CacheOrder>().Ctor<int>().Is(context => LoginHelper.LoginID); cfg.For<ICacheProduct>().Use<CacheProduct>().Ctor<int>().Is(context => LoginHelper.LoginID); cfg.For<ISQLOrder>().Use<SQLOrder>().Ctor<int>().Is(context => LoginHelper.LoginID); cfg.For<ISQLProduct>().Use<SQLProduct>().Ctor<int>().Is(context => LoginHelper.LoginID); Via constructor injection, a chain of objects can be created, with some needing an

Configuring StructureMap to generate and “remember” a constructor param literal

依然范特西╮ 提交于 2020-01-05 07:58:02
问题 I have a StructureMap config that looks something like: cfg.For<ICacheOrder>().Use<CacheOrder>().Ctor<int>().Is(context => LoginHelper.LoginID); cfg.For<ICacheProduct>().Use<CacheProduct>().Ctor<int>().Is(context => LoginHelper.LoginID); cfg.For<ISQLOrder>().Use<SQLOrder>().Ctor<int>().Is(context => LoginHelper.LoginID); cfg.For<ISQLProduct>().Use<SQLProduct>().Ctor<int>().Is(context => LoginHelper.LoginID); Via constructor injection, a chain of objects can be created, with some needing an

How to register and resolve multiple application life time scope objects with same interface and implementation?

纵饮孤独 提交于 2020-01-05 07:14:24
问题 There a quite a couple of similar questions but they don't seem to address this specific use case. From my configuration (run time), I am trying to create multiple instances of a certain object (same implementation, same interface) which should have an application life time scope. Reading the doc's I see Scoped lifetime (as per http request) Transient (as per resolvure) Singleton (application lifetime) So basically I need the singleton, but, I need multiple of them. The .AddSingleton method

How to register and resolve multiple application life time scope objects with same interface and implementation?

邮差的信 提交于 2020-01-05 07:14:07
问题 There a quite a couple of similar questions but they don't seem to address this specific use case. From my configuration (run time), I am trying to create multiple instances of a certain object (same implementation, same interface) which should have an application life time scope. Reading the doc's I see Scoped lifetime (as per http request) Transient (as per resolvure) Singleton (application lifetime) So basically I need the singleton, but, I need multiple of them. The .AddSingleton method

Optional object reference

旧时模样 提交于 2020-01-05 07:03:53
问题 I have a problem with my spring.net configuration: <object id="O1"> <constructor-arg ref="Dep1"/> <constructor-arg ref="Dep2"/> </object> This is part of my generic configuration used by all applications. Some applications define Dep2 in their configuration and some don't. Can I make second constructor arg return null (instead of reporting error) when specific application doesn't define Dep2? I would like to solve this without overriding O1 definition in app specific configuration. Thanks.

Declaring Facade Class in Dependency Injection

狂风中的少年 提交于 2020-01-05 05:55:44
问题 I am using Dependency Injection. Say that I has an OrderService class like this: public class OrderService{ public OrderService( IOrderValidator validator , IOrderRepository repository , IOrderNotificator notificator){ //assign global fields } public void SubmitOrder(Order ord){ if(validator.IsOrderValid(ord)){ repository.InsertNew(ord); notificator.Notify(ord); } } } Now I wonder to create a facade class for example TypeAOrderService , as inherited by OrderService, with components declared

How do I inject an abstraction using an IOC container like Dagger 2

别等时光非礼了梦想. 提交于 2020-01-05 05:55:22
问题 What I would like to do is to have an abstraction, and pass the abstraction as parameter. So that if one day something better than retrofit comes along and I want to switch it, it will be easy to do so. Although I have no idea on how do it. Here is a basic overview of what I want to do: public interface ApiClient{ Object getClient() } public class RetrofitClient implements ApiClient{ private static Retrofit retrofit = null; @Override public Retrofit getClient(){ if(retrofit == null){

How do I inject an abstraction using an IOC container like Dagger 2

前提是你 提交于 2020-01-05 05:54:23
问题 What I would like to do is to have an abstraction, and pass the abstraction as parameter. So that if one day something better than retrofit comes along and I want to switch it, it will be easy to do so. Although I have no idea on how do it. Here is a basic overview of what I want to do: public interface ApiClient{ Object getClient() } public class RetrofitClient implements ApiClient{ private static Retrofit retrofit = null; @Override public Retrofit getClient(){ if(retrofit == null){