dependency-injection

Internal dependency injection using Dagger2

本小妞迷上赌 提交于 2020-01-15 12:45:30
问题 I want to use Dagger2. Say I have the following dependencies: Class A depends on class B Class B depends on class C I tried to create a Module that provides B and C, and a Component that provides A, however only B is injected into A, and the reference to C in B remains null. What is the classes structure I need to implement using dagger? 回答1: You can either use constructor injection or field injection; and either constructor-inject or module-inject. Constructor-@Inject might be buggy, because

Internal dependency injection using Dagger2

瘦欲@ 提交于 2020-01-15 12:45:29
问题 I want to use Dagger2. Say I have the following dependencies: Class A depends on class B Class B depends on class C I tried to create a Module that provides B and C, and a Component that provides A, however only B is injected into A, and the reference to C in B remains null. What is the classes structure I need to implement using dagger? 回答1: You can either use constructor injection or field injection; and either constructor-inject or module-inject. Constructor-@Inject might be buggy, because

Autowiring services in Vaadin view and components not working

百般思念 提交于 2020-01-15 10:26:51
问题 Hello fellow programmers! I am relatively new to Vaadin so spare me please. I am trying to autowire my service layer into my view as follows: @Route("") @PWA(name = "First time bruh", shortName = "Project Base") public class MainView extends VerticalLayout { private TextField filterText = new TextField(); private Grid<Customer> grid = new Grid<>(Customer.class); private CustomerForm customerForm = new CustomerForm(this); @Autowired private CustomerService customerService; and the

How to use dependency injection in ActionFilter Web API?

坚强是说给别人听的谎言 提交于 2020-01-15 09:56:52
问题 I am trying to get work with dependency injection into the action filter, but it seems not working I've registered the type in UnityConfig public static void RegisterComponents(IUnityContainer container) { GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container); container.RegisterType<Domain.Contracts.IUserServices, Domain.UserServices>(new ContainerControlledLifetimeManager()); ... } The code is being called successfully, however, the instantiated object

Cannot use constructors in open generic services with Kephas

走远了吗. 提交于 2020-01-15 09:21:11
问题 Somehow I cannot get to make it work having a service exported as open generic with an implementation with a constructor. I tried to add the [CompositionConstructor] attribute to it to no avail. It throws something like: System.Composition.Hosting.CompositionFailedException : No importing constructor was found on type 'MyType'. Any ideas? 回答1: Unfortunately this is a bug in the System.Composition library (check here https://github.com/dotnet/corefx/issues/40094). As I can see, this bug is

Mediatr: reducing number of DI'ed objects

亡梦爱人 提交于 2020-01-15 03:53:08
问题 I have a lot of commands and queries and most of them need same interfaces DI'ed to do different things. Is it possible to some how reduce this clutter that each and every one of my handler needs and it is repeated over and over? public class GetCoinByIdQueryHandler : IRequestHandler<GetCoinByIdQuery, CoinModel> { private readonly EventsContext context; private readonly ICacheClient cache; private readonly ILogger logger; private readonly IMapper mapper; private readonly Settings settings;

Confusion with StructureMap 4.6 Transient Lifecycle

牧云@^-^@ 提交于 2020-01-15 03:52:04
问题 I am using StructureMap 4.6 as my IoC Container. I am a bit confused about its lifecycles. As I have read in its documentation, Transient will create a single instance of the object per container. Supported Lifecycles I am checking this scenario by creating a simple Console Application project. My code is as below: Program.cs class Program { private static IContainer _Container; static void Main(string[] args) { _Container = Container.For<ConsoleRegistry>(); var serv1 = _Container.GetInstance

Inject empty map via spring

走远了吗. 提交于 2020-01-15 03:47:05
问题 In my @Configuration file, I have beans with a relationship similar to the following: @Bean public Cache<Foo,Bar> fooBarCache(Map<Foo,Future<Bar>> refreshTaskMap) { return new AsyncUpdateCache(refreshTaskMap); } @Bean public Map<Foo,Future<Bar>> refreshTaskMap() { return new HashMap<Foo,Future<Bar>>(); } However, the ApplicationContext fails to load because it complains about "No qualifying bean of type [com.example.Bar]". From what I can tell, Spring is trying to be cute with creating a map

Jersey 2 + HK2 - @ApplicationScoped not working

痴心易碎 提交于 2020-01-15 03:33:08
问题 I have class @ApplicationScoped public class Service{ private Map<String, Integer> something ; private final Logger LOGGER = LoggerFactory.getLogger(Service.class); @PostConstruct public void initialize(){ something = new HashMap<>(); } public void increase(String userName){ something.put(userName, something.getOrDefault(userName, 0) + 1); } public Map<String, Integer> getSomething(){ return this.something; } public Integer getSomethingForUser(String userName){ return something.getOrDefault

HttpActionContext.get_Request() method not found when using Microsoft Asp.NET Dependency Injection

北慕城南 提交于 2020-01-15 03:08:47
问题 I am trying to add Microsoft Extensions Dependency Injection to an existing ASP.NET WebApi/Owin project. Following this blog post, I have added the ConfigureServices function, implemented DependencyResolver , and made HttpConfiguration instance to use it. Also I added all the non-abstract controllers to DI, and ensured they are instantiated using the DI mechanism. But after all these actions, requests to the application return error 500 with exception Method not found: 'System.Net.Http