dependency-injection

Constructor dependency Injection issue

我与影子孤独终老i 提交于 2021-01-28 06:01:06
问题 I am learning DI and new to spring while trying out CI I have written following code and I think I am correct in syntax still it's showing bean creation error. why it is unable to create bean..?? The code is Constuctor.java package beans; public class Constructor { private String name; private int age; private String email; public void Constructor(String name, int age, String email){ this.name=name; this.age=age; this.email=email; } public void show() { System.out.println("Name = "+name);

Can not inject workmanager constructor with Hilt

我是研究僧i 提交于 2021-01-28 05:48:14
问题 I'm developing an Android app. and I'm trying to use hilt with workmanager constructor but it does not work and gives me this error : 2020-08-18 19:01:09.989 18125-18759/com. E/WM-WorkerFactory: Could not instantiate example.android.app.database.DeleteNotesWorker java.lang.NoSuchMethodException: example.android.app.database.DeleteNotesWorker.<init> [class android.content.Context, class androidx.work.WorkerParameters] at java.lang.Class.getConstructor0(Class.java:2328) at java.lang.Class

ConfigurationProvider with other dependencies

馋奶兔 提交于 2021-01-27 20:04:30
问题 I've implemented my customs IConfigurationProvider and IConfigurationSource. public class MyConfigurationSource : IConfigurationSource { public string Foo { get; set; } public IConfigurationProvider Build(IConfigurationBuilder builder) { return new MyConfigurationProvider(this); } } internal class MyConfigurationProvider : ConfigurationProvider { public MyConfigurationSource Source { get; }; public MyConfigurationProvider() { Source = source } public override void Load() { // I'd like to

Spring dependency injection not working

自闭症网瘾萝莉.ら 提交于 2021-01-27 19:04:15
问题 I've got a problem in my standalone Java application. The thing is that I'm trying to Autowire both my Services and my DAOs, but I get a NullPointerException when I invoke service methods from the UI since dependency injection is not working properly. I've tried a lot of things, many of them from similar questions, but the problem is still there. I'm using Spring 4.0.6.RELEASE and Hibernate 4.3.11.Final. Here is my code: 1 - Invocation of service: public class LoginView { @Autowired private

Entity Framework Error when using Unity

落花浮王杯 提交于 2021-01-27 16:31:24
问题 On trying to resolve my service class, I'm getting an error that DbContext cannot be constructed because it's an abstract class. The error message is here: Unity.Exceptions.ResolutionFailedException: 'Resolution of the dependency failed, type = 'MyService.MyClass', name = '(none)'. Exception occurred while: while resolving. Exception is: InvalidOperationException - The current type, System.Data.Common.DbConnection, is an abstract class and cannot be constructed. Are you missing a type mapping

Many dependencies in service

不打扰是莪最后的温柔 提交于 2021-01-27 15:19:46
问题 I have trouble with dependencies in my application in service layer. I have following class: <?php class UserService{ private $userRepository; private $vocationService; private $roleService; public function __construct(UserRepository $userRepository, VocationService $vocationService, RoleService $roleService) { $this->userRepository = $userRepository; $this->vocationService = $vocationService; $this->roleService = $roleService; } } There are only three dependencies which I'm injecting. Assume

How to Inject dependencies in a Unity IoC container for SignalR hub?

折月煮酒 提交于 2021-01-27 14:41:55
问题 I have an application that is written with c# on the top of the ASP.NET MVC 5 Framework. I implemented Unity.Mvc into my project. Now, I am trying to inject dependencies objects into my SignalR Hub. I created a class called UnityHubActivator My class looks like this public class UnityHubActivator : IHubActivator { private readonly IUnityContainer _container; public UnityHubActivator(IUnityContainer container) { _container = container; } public IHub Create(HubDescriptor descriptor) { return

Why not inject IServiceProvider instead of each individual dependency?

流过昼夜 提交于 2021-01-27 07:06:02
问题 I am wondering why one wouldn't explicitly use the IServiceProvider to resolve dependencies over injecting each dependency individually. In other words, why use this approach: public class A { private B _b; private C _c; private D _d; private E _e; public A(B b, C c, D d, E e) { _b = b; _c = c; _d = d; _e = e; } } and not this: public class A { private B _b; private C _c; private D _d; private E _e; public A(IServiceProvider sp) { _b = (b) sp.GetService(typeof(b)); _c = (c) sp.GetService

How to inject DbContext instance in the ConfigureServices method of startup.cs correctly (ASP.net core 1.1)?

我是研究僧i 提交于 2021-01-27 07:03:04
问题 I have implemented the EntityFrameworkFileProvider for my ASP.NET core web application, I want the ViewDbContext instance to be injected by ASP.NET core DI framework in the constructor: ( ViewDbContext is a dbContext ) public class EntityFrameworkFileProvider : IFileProvider { private ViewDbContext _context; public EntityFrameworkFileProvider(ViewDbContext context) { /* should be injected by asp.net core DI */ _context = context; } public IDirectoryContents GetDirectoryContents(string subpath

Why not inject IServiceProvider instead of each individual dependency?

只谈情不闲聊 提交于 2021-01-27 06:54:47
问题 I am wondering why one wouldn't explicitly use the IServiceProvider to resolve dependencies over injecting each dependency individually. In other words, why use this approach: public class A { private B _b; private C _c; private D _d; private E _e; public A(B b, C c, D d, E e) { _b = b; _c = c; _d = d; _e = e; } } and not this: public class A { private B _b; private C _c; private D _d; private E _e; public A(IServiceProvider sp) { _b = (b) sp.GetService(typeof(b)); _c = (c) sp.GetService