dependency-injection

Generic Interface dependency injection into factory

徘徊边缘 提交于 2019-12-23 17:45:52
问题 I'm playing around with DI and Ninject. I'm open for suggestions on how to solve this in another way. I'm trying to make sure the concrete implementations of ICreateOrders can be replaced - if need be. Maybe there's another way or pattern? Solutions like this: C# - Ninject, IoC and factory pattern are fine but I was hoping to inject the possible creators into the factory and making the factory pick one based on OrderRequest. This doesn't work. kernel.Bind(typeof(ICreateOrders<,>)).To(typeof

Inject service into class (not component) Angular2

佐手、 提交于 2019-12-23 17:27:36
问题 I am struggling to find a way to inject a service into an class object in angular2. * NOTE: This is not a component, just a class. * export class Product { id: number; name: string; manufacturer: string; constructor(product: any) { this.id = product.id; this.name = product.name; this.manufacturer = product.manufacturer; } The only solution I have come up with is to pass the service reference to the constructor whenever I create a new product... ie: instead of new Product(product) I would do

ASP.NET Web Api Dependency Injection - Singleton or not

为君一笑 提交于 2019-12-23 17:06:51
问题 I am building a web api with asp.net and i am using the UnityContainer for handling dependencies. For example, my auth controller can depends on the auth service: class AuthController : ApiController { private IAuthService authService; public AuthController (IAuthService AuthService) { this.authService = AuthService; } ... } And the implementation of my auth service can depend on my user repository: class AuthController : IAuthService { private IUserRepository userRepository; public

Error injecting repository into service with Symfony3.3

扶醉桌前 提交于 2019-12-23 17:02:01
问题 I have an application that consists of a service layer and a repository layer. For both the services and the repositories I have declared interface and I inject the interface for services in the controller and services get injected with interfaces of the repositories. This is all done with autowire set to true. When I call a method on one of the injected services it all works fine, as long as I don't call a function that needs one of the injected repositories. When I try to call a function

Can a particular constructor argument of an injected SUT using Autodata xUnit Theories?

最后都变了- 提交于 2019-12-23 16:31:23
问题 Consider the following test, [Theory, MyConventions] public void GetClientExtensionReturnsCorrectValue(BuilderStrategy sut) { var expected = ""; // <--??? the value injected into BuilderStrategy var actual = sut.GetClientExtension(); Assert.Equal(expected, actual); } and the custom attribute I'm using: public class MyConventionsAttribute : AutoDataAttribute { public MyConventionsAttribute() : base(new Fixture().Customize(new AutoMoqCustomization())) {} } and the SUT: class BuilderStrategy {

UWP Template 10 and Service Dendency Injection (MVVM) not WPF

时光总嘲笑我的痴心妄想 提交于 2019-12-23 15:32:57
问题 I have spent over two weeks searching google, bing, stack overflow, and msdn docs trying to figure out how to do a proper dependency injection for a mobile app that I am developing. To be clear, I do DI every day in web apps. I do not need a crash course on what, who, and why DI is important. I know it is, and am always embracing it. What I need to understand is how this works in a mobile app world, and in particular a UWP Template 10 Mobile app. From my past, in a .net/Asp app I can

UWP Template 10 and Service Dendency Injection (MVVM) not WPF

痞子三分冷 提交于 2019-12-23 15:27:06
问题 I have spent over two weeks searching google, bing, stack overflow, and msdn docs trying to figure out how to do a proper dependency injection for a mobile app that I am developing. To be clear, I do DI every day in web apps. I do not need a crash course on what, who, and why DI is important. I know it is, and am always embracing it. What I need to understand is how this works in a mobile app world, and in particular a UWP Template 10 Mobile app. From my past, in a .net/Asp app I can

mvc core 2.0, how to use an appSettings.json file via configuration

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 15:02:15
问题 Today I was trying out the new asp.net core 2.0 but ran into some trouble using a JSON configuration file that I wasnt to inject in IConfiguration configuration constructor property. In asp.net core 1.1 I would use this following code in StartUp: public static IConfigurationRoot Configuration; Public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appSettings.json", optional: false, reloadOnChange: true) Configuration

java.io.FileNotFoundException: class path resource [WEB-INF/classes/library.properties] cannot be opened because it does not exist

*爱你&永不变心* 提交于 2019-12-23 14:55:24
问题 In my Spring application, I have a simple properties file located in folder WEB-INF\classes so that it, the DispatcherServlet and various other config files are in the classpath . The props file is defined in the DispatcherServlet as: <bean id="propertiesFactory" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="location"> <value>/WEB-INF/classes/library.properties</value> </property> </bean> The propertiesFactory bean is injected into a controller:

Func<Owned<T>> vs Func<T> dependency

半城伤御伤魂 提交于 2019-12-23 14:19:09
问题 I know that Func<T> is different from Func<Owned<T>> and I know how to inject a dependency of each type. However, I often get confused as in when shall I prefer one over the other? Assume, I have an application following MVP pattern and I want to inject a view PrintView . Then, on what grounds shall I decide that I should inject the view as Func<PrintView> or Func<Owned<PrintView>> ? 回答1: Func<T> will resolve an item from the lifetime scope that will be disposed when the lifetime scope is