Questions tagged [dependency-injection]

Dependency Injection is a collection of innovative software design principles and techniques that help diminish the dependency between various components within a system.

Phalcon's Swift_SmtpTransport is a powerful email transport tool

When attempting to integrate SwiftMailer with Phalcon 3 using the Dependency Injector, an error related to the Swift_transporter Service is encountered. Error: Service 'Swift_SmtpTransport' not found in the dependency injection container I am interest ...

Troubleshooting: Issues with Angular 2 Dependency Injection

I am facing an issue with my angular2 application that involves a simple dependency injection, but it seems to be not working correctly. Can anyone help me figure out what might be missing? Below is the error message I am encountering: EXCEPTION: Cannot ...

Exploring the Concept of Dependency Injection in Angular 2

Below is a code snippet showcasing Angular 2/Typescript integration: @Component({ ... : ... providers: [MyService] }) export class MyComponent{ constructor(private _myService : MyService){ } someFunction(){ this._mySer ...

Service function in Angular 2 is returning an undefined value

There are two services in my project, namely AuthService and AuthRedirectService. The AuthService utilizes the Http service to fetch simple data {"status": 4} from the server and then returns the status number by calling response.json().status. On the ot ...

What is the process for integrating a factory into a controller?

Hello, I'm currently new to working with angularjs and I'm facing some challenges while trying to inject a factory into my controller. The factory seems to be functioning properly as I can set data in it without any issues. Below is the code snippet where ...

Singleton Pattern in Angular Dependency Injection

In my code, I have a service called MyService that is decorated with the following: @Injectable({ providedIn: 'root' }) Part of its implementation includes: private myData: string = ''; setData(data: string) { this.myData = d ...

Error: $controller does not function as a controller within another controller

I recently started learning Angular JS and attempted to call one controller within another, but encountered the following error: ionic.bundle.js:21157 TypeError: $controller is not a function at new <anonymous> (http://localhost:8080/itravel/www/js/ ...

Challenges with Dependency Injection in Symfony 4.1 Components

Currently, I am in the process of updating an older PHP application. I am attempting to utilize Symfony's dependency injection component to inject services into controllers (and other services), but I am encountering difficulties as the Symfony docum ...

Extending parent context in dependencies through OOP/Typescript as an alternative to using "extends"

Introducing a custom class called EventBus has been a game-changer for me. This class allows for easy attachment of on/off/once methods to any class that extends it, enabling the creation of an array of events that can be listened to. Currently, I find my ...

Solving Angular2 Dependency Issues

I'm curious about Angular 2 and whether there's a way to resolve dependencies without having to use the constructor. In .NET, you can inject dependencies in three ways (constructor, setter, interface-based). Is it possible to do setter injection in Angul ...

The perfect combination: Symfony2 and AngularJS working together

Currently, I have been working on a web app that utilizes Symfony2 and recently integrated AngularJS. Within this app, there is an input field where users can filter products by name. The issue arises when it comes to querying the database in PHP and passi ...

What is the proper way to annotate a controller so that it functions correctly when minified, especially when it relies on a combination of objects from Angular and a resolve method?

I'm facing an issue with wiring up the modalController properly to Angular's DI container. My angular view looks like this: <div ng-controller="myController"> {{helloWorld}} <br /><br /> <button type='button ...

Injecting dependencies into an abstract class in typescript using Angular 2

So I have an abstract class that doesn't have a constructor, and my goal is to inject another class into it. Here's the abstract class: import { ErrorHandler } from '../../shared/services/errorHandler.service'; import { Inject } from '@angular/core'; e ...

Adjust the component suppliers based on the @input

If I were to implement a material datepicker with a selection strategy, I would refer to this example There are instances where the selection strategy should not be used. The challenge lies in setting the selection strategy conditionally when it is insta ...

Angular replaces the expected service with the value `false` instead of injecting the desired service

I have a controller defined like this: angular.module('myApp') .controller 'DetailController', ($rootScope, $scope, $routeParams, apiService) -> onStart = () -> fetchData() getAdditionalData() # more functions are defined here ...

Avoiding the pitfalls of hierarchical dependency injection in Angular 6

Too long; didn't read: How can I ensure that Angular uses the standard implementation of HttpClient in lower level modules instead of injecting a custom one with interceptors? I have developed an Angular 6 library using Angular CLI. This library exports a ...

Injecting Dependencies in Angular 2 Without Using the Constructor

Exploring DI in Angular 2 has led me to implement a REST-Client using generic subtypes for concrete Datatypes like this: class RESTClient<T>{ constructor() { var inj = ReflectiveInjector.resolveAndCreate([HTTP_PROVIDERS]); this. ...

Is the RouterModule exclusively necessary for route declarations?

The Angular Material Documentation center's component-category-list imports the RouterModule, yet it does not define any routes or reexport the RouterModule. Is there a necessity for importing the RouterModule in this scenario? ...

Circular Dependency Detected in Angular 7 Library: A Tight Web of Directive, Service, and Module Interconnections

After setting up a new Angular 7 project with a library that includes a directive, a service, and a module (where the directive gets the service injected and the service has an injectionToken exported in the module), I encountered these warnings during com ...

Injecting Window into Angular 2.1.0: A Step-by-Step Guide

Previously, in the earlier RC versions of Angular 2, I was able to easily inject the window object by including {provide: Window, useValue: window} In the providers array. However, after updating to the latest stable release of Angular 2 (2.1.0), this no ...

Tsyringe - Utilizing Dependency Injection with Multiple Constructors

Hey there, how's everyone doing today? I'm venturing into something new and different, stepping slightly away from the usual concept but aiming to accomplish my goal in a more refined manner. Currently, I am utilizing a repository pattern and looking to ...

struggling with configuring dependency injection in NestJS and TypeORM

Struggling with integrating nestjs and typeorm for a simple CRUD application, specifically facing issues with dependency injection. Attempting to modularize the database setup code and import it. Encountering this error message: [ExceptionHandler] Nest ...

Utilizing Vue and Typescript for efficient dependency injection

After attempting to use vue-injector, I encountered an issue as it was not compatible with my version of Vue (2.6.10) and Typescript (3.4.5). Exploring other alternatives, there seem to be limited options available. Within the realm of pure typescript, t ...

What steps can be taken to solve a circular dependency issue in NestJS?

In my application setup, I have an app.module which brings in both UserModule and AuthModule. @Module({ imports: [UserModule, AuthModule], controllers: [AppController], providers: [AppService], }) export class AppModule {} Let's take a closer look a ...

Unable to construct wheels for dependency-injector, a prerequisite for the installation of pyproject.toml-dependent projects

Seeking help with an error that keeps occurring while I attempt to install the "dependency-injector" package for my project, (env) PS C:Multi-Participants_Survey_Project-main-2djangosurveybackend> pip install dependency-injector Collecting dependency- ...

Embedding external dependencies into a Node module at the application level

I am currently facing a challenge in creating packages from higher-order components within my application. The issue arises when some of these components use application routes, accessed through a helper that imports all the routes and returns URLs based ...

Creating PHP Objects with the Factory Method and Using Dependency Injection

I am in search of an effective pattern for creating database-bound objects. To illustrate, let's consider the process of creating a user. First: Implementing a Factory method to Create/Load a user. User configuration is set within the new instance. $user ...

Dependencies in Angular

After diving into Angular recently, I've been grasping the concepts well. However, one thing that still puzzles me is dependency injection. I'm unsure whether it's necessary to declare all components of my application (services, controllers ...

Mastering Dependency Injection for League Flysystem Integration

The goal is to develop a unique Reader class that functions as a wrapper for the League Flysystem documentation The purpose of the Reader is to provide a convenient way of reading all files in a directory, regardless of their physical form (local file or ...

Introducing the First Angular Factory

It's high time for me to finally inject my first angular Factory . . . Here is the code I have: .factory('Debts', function($q, $scope){ return MA; }) .controller('Admin', function ($scope, Debts) { $scope.Debts = Debts; $scope.Debts.MA ...

Utilizing Angular resolver to inject the router functionality

In my Angular (v13) application, I have defined a resolver to interact with a Wordpress backend. The purpose of this resolver is to determine the post type and ID from Wordpress when a user accesses a URL, and then route accordingly (to a post list, single ...

Is there a way to create fresh instances of a class using Injector rather than utilizing a singleton pattern?

In my Angular application, I am working with two injectable classes. @Injectable() class B {} @Injectable() class A { constructor(b:B) { } } My goal is to make class A a Singleton and class B a Transient. I recently discovered that I can utilize Ref ...

Angular: Creating an instance of a class with StaticProvider passed as a parameter

Having trouble instantiating a class with a StaticProvider. Here's the code snippet: main.ts export function createProvider() { // some implementation return result; // result is a string } const providers = [ { provide: 'TEST', useFactory: c ...

Angular Dependency Injection: Individual instances of each service are provided for every module usage

Within my application, there is a module called "FileUpload". The upload service included is "UploadService", which receives a service injection with the interface "RequestService." I also have two other modules: FileManager1 and FileManager2. Each file m ...

Using Angular's built-in dependency injection with the $resource factory allows for

Question regarding Dependency Injection on factory resource: As far as I know, the following example is the recommended approach for injecting dependencies in Angular1: angular.module('myApp').factory('Resource', Resource); Resource. ...

What methods can be used to reduce the number of dependencies passed to a controller effectively?

Trying to streamline my Silex code, I am working on removing the $app parameter from my controller actions and only passing in the necessary dependencies. Typically, my controllers rely on these common dependencies: Template engine Session provider Tran ...

Declaration of dependencies for NestJS must include dependencies of dependencies

I'm encountering an issue where NestJS is not automatically resolving dependencies-of-dependencies: I have created an AWSModule which is a simple link to Amazon AWS with only a dependency on the ConfigService: @Module({ imports: [ConfigModule], con ...

Using InjectionToken within an Angular APP_INITIALIZER function

I am currently working on implementing an APP_INITIALIZER in my Angular 10 project. The factory function I'm using has multiple dependencies, one of which is an InjectionToken<string>. However, I have encountered an issue when trying to inject it sim ...

The Nest.js Inject decorator is not compatible with property-based injection

I am facing an issue with injecting a dependency into an exception filter. Here is the dependency in question: @Injectable() export class CustomService { constructor() {} async performAction() { console.log('Custom service action executed ...

How can we use tsyringe (a dependency injection library) to resolve classes with dependencies?

I seem to be struggling with understanding how TSyringe handles classes with dependencies. To illustrate my issue, I have created a simple example. In my index.tsx file, following the documentation, I import reflect-metadata. When injecting a singleton cl ...

Is it possible to implement dependency injection within a .css document?

I have a C# .NET 6 application. Some of the web pages (Razor Pages) in the app use dependency injection to inject configuration into the Razor Pages (.cshtml files), allowing certain config elements to be displayed in the user interface. My query is, can ...

Building custom directives on AngularJS pages without a specified ng-app module

On some of my basic pages, I don't need to specify a particular application module in the ng-app attribute. However, these pages do utilize some custom directives that I have created. To keep things organized, I have placed all of my directives within a s ...

Angular: InjectionToken for service injection causes issue

Angular version: 4.4.6 Edit: This example may appear complex and not relevant to some readers. TL;DR: I encountered a problem where my service could not be dynamically injected because it was not provided by any module. This confusion stemmed from trying ...

Encountering a type 'any' issue with the Authentication guard injection in Angular 17

I implemented a functional guard in Angular 17 import { Inject } from '@angular/core'; export const checkoutGuard: CanActivateFn = (route, state) => { const customerService = Inject(CustomerService); const router = Inject(Router); ...

How to achieve dynamic class instantiation through constructor injection in Angular 8?

Despite my efforts to find a solution, my understanding of Dependency Injection in services is still limited, making it challenging to get this thing working. I'm left wondering if there's any way to make it work at all. My current setup involve ...

Laravel - Creating custom middleware for typed Request parameters

I am looking to utilize the VacancyListRequest in order to pass middleware parameters and validate them using its rules before reaching the controller action. While I understand that middleware follows the Pipeline pattern, I am unsure how to use a custom ...

Guide to Implementing Dependency Injection in Angular 2

When working with Angular Components written in TypeScript, it is possible to declare a class member (variable) as a parameter of the constructor. I am curious about the reason for doing so. To clarify, take a look at the examples below. Both achieve the ...

Struggling with injecting $q into AngularJS?

Hey everyone! I've encountered a puzzling issue that I need help with. I'm attempting to inject the $q library into one of my controllers, but when I try to console.log() it, it shows up as "undefined". Oddly enough, I am successfully injecting the same l ...

Facing challenges with parsing JSON files in an Angular 2+ application

Utilizing the Angular CLI, I have configured this project with the standard folder layout. My goal is to practice reading a JSON file from src/app/assets/items.json and then using it to display these items in the HTML. items.json: { "results": [ ...

Angular 2 - Circular dependencies leading to the error message "unexpected value undefined"

Currently, I am organizing my app using shared, features, and core modules. The structure of my SharedModule appears as follows: @NgModule({ declarations: [ TendanceNotePipe, ColorNotePipe, ], exports: [ CommonModule, FormsModule, ...

Injecting dependencies through the Angular factory method allows for seamless

I'm in the process of transferring some standard navigation formatting code from the controller to a factory. Should I include $scope in my factory? Despite numerous attempts, I have been unsuccessful in injecting $scope using various methods. Do my ...

Utilize the provider within the decorator function

Essentially, the challenge I am facing is passing an authService to the "verifyClient" function within the @WebSocketGateway decorator. Here is how it should look: @WebSocketGateway({ transports: ['websocket'], verifyClient: (info: { req: IncomingMessa ...

What methods does Json.NET use to implement dependency injection while deserializing?

Is it possible for Newtonsoft.Json to create an object of a class that has no default constructor and uses dependency injection to pass its dependencies? Take the following example: public class SomeFoo { private readonly IFooDependency _dependency; ...

Utilizing Angular's Dependency Injection in Component Development

Can component injection be achieved in AngularJS using dependency injection? There is a SignalR hub factory that I want to use for injecting my SignalR hub proxy. Below is the code snippet where I am creating an ngTable Component that needs to be updated ...

Properties cannot be accessed using the standard method in the controller; however, they function correctly when using an arrow

Currently, I am facing a challenge where traditional class methods do not allow me to access the userService. I aim to write typical class methods in my user controller like this: public async register(req: Request, res: Response, next: NextFunction): Pr ...

Lazy-loaded modules in Angular that contain services provided within the module

Currently, I am facing a challenge with lazy-loaded modules and services that are provided in these modules. My folder structure looks like this: app -> featureModule1 (lazy loaded) -> featureModule2 (lazy loaded) -->services --->servi ...

Embedding services into Entities: Verifying the presence of an image file

Currently, I am working with PHP and the Doctrine ORM. The situation at hand involves a product table that has an image field. My goal is to create an event that verifies whether an image exists in my assets cloud storage (specifically Amazon S3). If the f ...

Issue with InversifyJS @multiInject: receiving an error stating "ServiceIdentifier has an ambiguous match"

Having an issue with inversifyJs while trying to implement dependency injection in my TypeScript project. Specifically, when using the @multiInject decorator, I keep receiving the error "Ambiguous match found for serviceIdentifier". I've been referenc ...

Utilizing the Injector for Quality Testing Services

After bootstrapping my service before its dependency, I rely on the Injector to handle the dependency once it's ready. constructor(private readonly injector: Injector) { const interval = setInterval(() => { const myService = injector.get(MyServic ...

Acquire multiple instances of NestJs dependencies using dependency injection within a single class

Below is a class called Product @Injectable() export class Product { brand: string; } I am injecting the Product class into ProductService export class ProductService { constructor(private readonly product: Product) {} update(products) { ...

I'm finding it difficult to grasp the purpose of $inject within controllers

I'm feeling completely lost when it comes to understanding inject in Angular. I can't seem to grasp where it should be utilized and its purpose. Is it specifically tied to factory methods, as outlined here? myController.$inject = ['$scope','notify']; In ...

Struggling to implement a singleton service in Angular as per the documentation provided

I have implemented a service in Angular that I want to be a singleton. Following the guidelines provided in the official documentation, I have set the providedIn property to "root" as shown below: @Injectable({ providedIn: "root" }) export class SecuritySe ...