Questions tagged [dependency-injection]

10440 questions
1

votes
2

answer
382

Views

NestJS - Injected service is undefined in the constructor

As per the documentation, I inject a service in a controller's constructor, but it turns out as undefined. processScraped.controller.ts import { Controller, Post, Body } from '@nestjs/common'; import { ProcessScrapedService } from './processScraped.service' console.log(`\nController - ProcessScraped...
Jeremy Thille
1

votes
2

answer
1.9k

Views

How to read connection string inside .NET Standard Class library project from ASP.NET Core

In my solution, I have a ASP.NET Core web project and a .NET Standard class library project. Class library project is the data access layer and I want to read the connection string from my appsettings.json (ASP.NET Core project) in my data access layer. I have found few answers such as by Andrii Li...
Learning Curve
1

votes
3

answer
107

Views

How dependency injection in Angular is useful since it doesn't solve anything apparently?

How this can improve my code? How it can remove dependency ? I still don't see any benefit of using this ? @Component({ selector: 'talk-list', templateUrl: 'talks.html', providers: [TalksAppBackend] }) class TalkList { constructor(backend:TalksAppBackend) { this.talks = backend.fetchTalks();...
Jameela Khan
1

votes
2

answer
142

Views

Dependency injection in UIViewControllers iOS swift

First I checked this post and it wasn't useful I want to apply dependency injection on navigation from a controller to another, let's say I have controller A : import UIKit class A: UIViewController { } and a controller B : import UIKit class B: UIViewController { var name : String! } I'm naviga...
MhmdRizk
1

votes
2

answer
76

Views

Defining an 'HttpClient' singleton via StructureMap causes an error about 'HttpMessageHandler' being not configured in runtime

Trying to define an HttpClient singleton in StructureMap ala: For().Singleton().UseIfNone(); This results in the following error in runtime (upon dependency injection): StructureMap.StructureMapConfigurationException: No default Instance is registered and cannot be automatically determined for type...
XDS
0

votes
1

answer
47

Views

Does Dependency Injection (DI) only transfer dependency-problems?

I have a problem with fully understanding DI. Let’s assume I have a deeply nested application (10 Layers) Each layer is designed against an interface. e.g.: class Layer3 : InterfaceLayer3 {….} Each layer gets it’s dependencies to the next layer injected via constructor-injection. e.g.: Layer...
TomFan
1

votes
1

answer
65

Views

ASP.NET Core DI with Simple Injector sharing DbContext

I'm setting up an ASP.NET Core project and following a CQRS pattern basing my work on the Tripod project. I've followed the Simple Injector integration guide but a little puzzled on one point... I want to keep make use of the UseInMemoryDatabase option for testing and can only find examples of that...
Stephen York
1

votes
2

answer
57

Views

How do I provide extra parameters with Ninject?

I need to auto-resolve dependencies of my windows form. The only problem is my forms constructor expects an integer value as well. Please have a look at the implementation in the code section. //Ninject bindings public class Bindings : NinjectModule { public override void Load() { Bind().To(); Bind(...
void
1

votes
1

answer
18

Views

function name for @Provides Method in Guice

With @Provides annotation, I am curious what is the function name requirement. @Provides TypeA ProvideTypeA() { ... return TypeA } Is it OK to use a different function name? @Provides TypeA AnyName() { ... return TypeA }
derek
1

votes
1

answer
41

Views

Dependency Injection: No Service for type

I'm trying to separate the concerns across my application and I thought this answer by Steven fits my scenario beautifully but I'm trying to remove the ninject element: Validation: How to inject A Model State wrapper with Ninject? I've added all required classes from the answer. I've got my service...
Smithy
0

votes
0

answer
3

Views

Scoping StructureMap Container to Maintain DbContext Correctly

My application uses StructureMap for dependency injection. It is a large application...and after looking at PerfMon stats...it seems StructureMap is creating a LOT of instances of the DbContext. As such, I am trying to ensure the SAME instances are created across all classes...but no matter what...
Prisoner ZERO
0

votes
0

answer
288

Views

NestJS : Inject Service into Models / Entities

i am currently stuck on a problem, which i don't know how to propery solve: In my NestJS application, I would like to make all my TypeORM Entities extend a BaseEntity class that provide some general features. For example, i would like to provide an additional getHashedID() method that hashed (and th...
zorn
0

votes
1

answer
9

Views

Nestjs cant resolve dependencies

Can't figure out what's the problem of my code. (I'm new with nestjs, I'm trying to learn it by passing some apps to it). Console log says: Nest can't resolve dependencies of the UrlsAfipService (?). Please make sure that the argument at index [0] is available in the ApiModule context. UrlsAfipServi...
Marcelo J Forclaz
-2

votes
2

answer
51

Views

Create a new instance of class on calling a method

I have a Console Application which is injecting all the services through the constructor. I am also creating and initializing a Dictionary in the Constructor of my data access class. I am calling the data access method from my main class but I wanted to create a new instance of data access class and...
JamieB
1

votes
1

answer
1.8k

Views

Get a service in a IServiceCollection extension

I have this extension public static class ServiceCollectionExtensions { public static IServiceCollection MyExtension(this IServiceCollection serviceCollection) { ... } } and I need to get information from a service like this: services.AddAuthentication(options => { options.DefaultAuthenticateScheme...
andres descalzo
1

votes
1

answer
539

Views

C# Unity - change concrete implementation at runtime

I'm having a little bit of trouble wrapping my head around IoC - specifically using Unity. Suppose I have an application that I want to use to send emails. I would model it like this: public interface IEmailSender { void SendEmail(); } And then create some implementations of the interface: public cl...
MillinMo
1

votes
3

answer
1.4k

Views

Best way to inject instance of DynamoDBContext in .NET Core

Currently working on a web services project for my class and have decided to make a web API using .NET Core and DynamodDB. I was just curious what the best way to inject the DynamoDBContext is? I currently am doing it like this: public void ConfigureServices(IServiceCollection services) { services.A...
wjvukasovic
1

votes
1

answer
247

Views
1

votes
1

answer
115

Views

How to inject dependencies with XmlSerializer and autofac?

I have a class named SomeRule that can be serialized in a XML format. The class uses an ISomeService that I would like to be injected via autofac. [Serializable] public class SomeRule { [XmlAttribute('Attribute1')] public string Attribute1 {get;set;} [XmlAttribute('Attribute2')] public string Attri...
Kzrystof
1

votes
2

answer
45

Views

Using DI in AspNET Core

I have a derived class of DbContext, called NavigationContext, that looks like this: public class NavigationContext : DbContext { private readonly IConfiguration _configuration; public NavigationContext(DbContextOptions options, IConfiguration configuration) : base(options) { _configuration = config...
Riddari
1

votes
1

answer
132

Views

ASP.NET Core SignalR acces Hub method from anywhere

If been spending many hours on this problem and I found a lot of different strategies, but none of them worked for me. (This code is just a proof of concept ofcourse.) I have the following setup using Asp.net core 2.1 (on .Net Framwork 4.7.2): I have made a signalr hub which has a method to send a n...
MrEighteen
1

votes
1

answer
36

Views

Expose private method when doing dependency injection

I've got a template class 'Foo' and another non template class 'Bar'. I want to have instance of Bar inside of Foo and expose one of Bar's functions that is private only to Foo. Example: template class Foo { std::shared_ptr m_bar; bool Func() { return m_bar->DoSomething(); } } class Bar { private:...
CyberGK
1

votes
0

answer
787

Views

How to use dependency injection in ActionFilter Web API?

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)...
M005
1

votes
0

answer
75

Views

Is Dependency Injection with AngularJS and Webpack superfluous?

I'm working on an AngularJS application and trying to convert it from a Gulp bundling system over to Webpack. I've been searching for some time now for arguments for/against utilizing the AngularJS dependency injection in tandem with require() statements for Webpack dependency graphs. Why might some...
Andrew Craswell
1

votes
1

answer
629

Views

Spring-Boot: configure Log4j2 to use Spring-Boot DataSource

I'm building an application using Spring-Boot (1.5.9-RELEASE) and I want to use log4j2 with it. I want to configure log4j2 to log to a database table using a JDBC connection. My issue is that I am unable to configure log4j2 to use the DataSource I have configured for Spring-Boot. I know that log4j2...
MattWeiler
1

votes
1

answer
183

Views

How to use inversifyjs container as service locator

I'm writing socket server for my IOT project (stm32f100 + WIFI esp) I have implemented communication protocol such as GET query: method=test&data[]=1&data[]=2...etc I want to implement method resolver which will fetch service (controller) by method name from inversifyjs container with it's dependenc...
Nick Muntyanov
1

votes
1

answer
233

Views

Structuremap - dependency injection - EF Core DBContext lifetime per request

Has anyone had any luck setting up an EF Core DBContext with Structuremap 'correctly' (what is correctly?) DBContext needs to be a singleton across the lifetime of the request. I understand that the default lifecycle is Transient. I understand that that will get a nested container, which effectively...
jenson-button-event
1

votes
0

answer
56

Views

dependency injection between modules

in Android project I have two modules: app core App module build.gradle is using core module with: implementation project(':core') So I can use core module classes in app module In core module I have class A that uses class B (also in core module). I want to add class C in module App extending class...
taulus
1

votes
0

answer
139

Views

How do I inject ReactiveMongoApi trait in a Repository with macwire?

I'm new to Play framework and all the Scala stack. I'm trying to implement dependency injection using macwire and ReactiveMongo to handle my MongoDB database. I have this classes to define repositories. trait BaseRepository extends ReactiveMongoComponents { /** * collection to retrieve documents fro...
Marcos
1

votes
0

answer
357

Views

Asp Net Core DI for AutoMapper

I have a question regarding dependency injection for AutoMapper in ASP NET Core. I know that there is automapper extension for DI available when implementing custom IValueResolver and IMemberValueResolver. This works only if the custom value resolvers are created by AutoMapper/DI. This unfortunately...
Ehab Kashkash
1

votes
1

answer
184

Views

Dependency injection in Jenkins development

I'm working on an (existing) Jenkins plugin and would like to use dependency injection. Unfortunately, DI for Jenkins development is poorly documented. As far as I know Jenkins uses Google's Guice framework for DI. There is this Wiki page, but I'm a little puzzled about it: in existing Jenkins plugi...
Boon
1

votes
0

answer
132

Views

Registering and consuming single instance with various dependencies with Autofac in ASP.NET application

I want to have a single instance of WorkerContainer class that injects various worker implementations. I want to get this instance in Global.asax and start workers. public class WorkerContainer { IWorker[] _workers; public WorkerContainer(IWorker[] workers)//DI { _workers = workers; } public void St...
vpetrovic
1

votes
2

answer
499

Views

Dependency Injection using ninject not working

My goal is simply this: I want the already existent instance of class 'MainWindowVM' (implementing IMainWindowVM) to be injected into class 'StaticTestsResultsViewModel'. I do not(!) want a new instance of class 'MainWindowVM' to be instantiated. Instead, I want the already existent instance of this...
steady_progress
1

votes
1

answer
79

Views

Guice binding and FactoryModuleBuilder

I am a trying to use Guice (newbie here!!) for one of my projects. so I have a interface Consumer{ } and my implementations are class XMLConsumer implements Consumer { XMLConsumer(DataQueue queue){ } } I also have the DataQueue interface defined as interface DataQueue { } and the implementatio...
RKN
1

votes
0

answer
193

Views

Inject variable from service in environment.ts

I have an Angular 5 app which needs to load some config files from a service (from VSTS) before the app actually starts. I do this by loading a JSON file on bootstrap in app.module.ts: // above the NgModule-decorator export function init(settingsProvider: SettingsProvider) { return () => settingsPro...
dave0688
1

votes
2

answer
110

Views

Common code for dependency injection for web api, admin panel and mvc controller

Currently, I have below 4 projects in my solution file : API (Web API) Web (MVC) Admin (MVC) Service Layer (C# Library) The service layer is being used by all the 3 web projects. The service is injected using Autofac container. The services are registered in each of the web projects during startup w...
user3151766
1

votes
0

answer
135

Views

Wiring up Autofac in MonoGame

I'm attempting to wire up Autofac v4.6.2 in MonoGame v3.6. This is what I have in my program.cs public static class Program { private static IContainer Container { get; set; } [STAThread] static void Main() { var builder = new ContainerBuilder(); builder.RegisterType().InstancePerLifetimeScope().Pro...
John Geddes
1

votes
1

answer
33

Views

IoC Deciding specific implemetation at runtime

I would like to implement some inversion of control in my framework. So I have an interface GenericDatabase that defines the methods that have to be implemented. I do not know in advance which classes will implement this, but I have the methods that will call the interface methods. So at runtime I n...
user1156544
1

votes
1

answer
116

Views

Symfony 3.3 - Services.yml Argument (ResponseFactory) - Parameter Being Passed In As String Instead of Object

The Error Hello, I am getting the following error: Type error: Argument 2 passed to ApiExceptionBundle\EventListener\ApiExceptionSubscriber::__construct() must implement interface ApiExceptionBundle\Component\Factory\ResponseFactoryInterface, string given, called in C:\htdocs\projects\myproject\var\...
khgm13
1

votes
2

answer
875

Views

Symfony 3.4.3 - service container: Error requires that you provide a value for the

i spent a lot of time but i did not solve it I would like to pass LoggerInterface in the action of my controller here is my service.yml # Learn more about services, parameters and containers at # https://symfony.com/doc/current/service_container.html parameters: #parameter_name: value services: # de...
BruceStackOverFlow

View additional questions