inversion-of-control

Ninject - Multiple Classes Using Single Interface (more than one matching bindings are available)

限于喜欢 提交于 2020-01-05 09:33:14
问题 If I have an implementation of Human and Dog class which uses the IPerson interface and HumanFood and DogFood class using the IFood interface. How can I switch from using HumanFood to DogFood and Human to Dog in my main function? Currently the way this is written it is giving me a "more than one matching bindings are available" error. Thanks! public class Bindings : NinjectModule { public override void Load() { this.Bind<IFood>().To<HumanFood>(); this.Bind<IFood>().To<DogFood>(); this.Bind

registering DbContext with multiple parameters

蓝咒 提交于 2020-01-05 04:51:05
问题 I'm trying to inject TenantProvider into DbContext public class AppDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, long> { public int? _tenantId; public ITenantProvider _tenantProvider; public AppDbContext( DbContextOptions<AppDbContext> options, ITenantProvider tenantProvider ) : base(options) { _tenantProvider = tenantProvider; } but I don't understand how to register it correctly - if I put the breakpoint in the constructor - tenantProvider is null . The bit from Startup.cs

Should thoses kind of service go injected in a base class ? (versus static classes)

瘦欲@ 提交于 2020-01-04 15:15:20
问题 I was wondering.. if i have services such ILoggingService, IMailerService, ICacheService. Those are part of the infrastructure somehow. However, would you make them as a static class or would you inject them in a base class so that all derived classes get access to them as singleton ? How do you handle them ? 回答1: Dependencies often represent infrastructure components. Not only emailing, but data access of any kind can be considered part of the infrastructure. Such Services are best kept as

Creating stub for `private static readonly` field

主宰稳场 提交于 2020-01-04 07:35:51
问题 Due on Improper Instantiation problem it is recommended to create private static readonly instance of HttpClient . Due on lack of time I have injected mocked client into test method with client as their parameter. The problem is how can I in simple way inject mock into private static readonly HttpClient field of SingleHttpClientInstanceController ? 回答1: how can I in simple way inject mock into private static readonly HttpClient field of SingleHttpClientInstanceController ? Answer: There is no

Creating stub for `private static readonly` field

橙三吉。 提交于 2020-01-04 07:35:17
问题 Due on Improper Instantiation problem it is recommended to create private static readonly instance of HttpClient . Due on lack of time I have injected mocked client into test method with client as their parameter. The problem is how can I in simple way inject mock into private static readonly HttpClient field of SingleHttpClientInstanceController ? 回答1: how can I in simple way inject mock into private static readonly HttpClient field of SingleHttpClientInstanceController ? Answer: There is no

C# and IoC transitive dependencies removed

人盡茶涼 提交于 2020-01-04 04:34:19
问题 I have a solution in which I use IoC (windsor). The projects in the solution are as follows: Interfaces - Holds all the interface contracts I'll use. IoC.Installers - Holds all the installers for my dependencies (has reference to impl. and interfaces) IoC - Holds a singleton class that holds the IoC container. The class performs the initialization process of the container. Console - The project that uses the IoC to resolve dependencies (has reference to interfaces an IoC) The problem: Because

NserviceBus property injection

末鹿安然 提交于 2020-01-04 02:14:06
问题 I am attempting to inject an object into my saga. Using the following endpoint, when the message arrives at the handle method of the saga the property is null. The endpoint: public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantToRunAtStartup { public void Run() { IOrderRepository orderRepository = new OrderRepository(); Configure.Instance.Configurer.ConfigureProperty<CreateOrderSaga>(x => x.OrderRepository, orderRepository); } // stop method removed } The app.config <?xml

Sharing instance of class between other classes in Castle Windsor

怎甘沉沦 提交于 2020-01-03 19:45:31
问题 I'm trying to figure out the best way to share an instance of a class between two other classes that depend on it. Say I have these classes: class A { public A(B b, C c) {} } class B { public B(IDFactory factory) {} } class C { public C(IDFactory factory) {} } interface IDFactory { D GetD(); } class D {} And for each instance of A , I want the D used by c and d to be a single instance of D . When I create a new instance of A (say using a factory), I want c and d to share a new instance of D.

Sharing instance of class between other classes in Castle Windsor

ぃ、小莉子 提交于 2020-01-03 19:44:51
问题 I'm trying to figure out the best way to share an instance of a class between two other classes that depend on it. Say I have these classes: class A { public A(B b, C c) {} } class B { public B(IDFactory factory) {} } class C { public C(IDFactory factory) {} } interface IDFactory { D GetD(); } class D {} And for each instance of A , I want the D used by c and d to be a single instance of D . When I create a new instance of A (say using a factory), I want c and d to share a new instance of D.

Sharing instance of class between other classes in Castle Windsor

走远了吗. 提交于 2020-01-03 19:44:05
问题 I'm trying to figure out the best way to share an instance of a class between two other classes that depend on it. Say I have these classes: class A { public A(B b, C c) {} } class B { public B(IDFactory factory) {} } class C { public C(IDFactory factory) {} } interface IDFactory { D GetD(); } class D {} And for each instance of A , I want the D used by c and d to be a single instance of D . When I create a new instance of A (say using a factory), I want c and d to share a new instance of D.