Skip to content

API Reference


API Reference / @dasch-ng/utils / src / provideType

Function: provideType() ​

provideType<T>(provide, options?): ConstructorProvider

Defined in: libs/ng/utils/src/lib/provide-helpers.ts:240

Creates a type-safe constructor provider for Angular dependency injection.

This is a simplified provider for cases where the token and implementation class are the same. It's equivalent to providing a class directly but allows explicit dependency configuration when needed.

Type Parameters ​

T ​

T

The class type to provide

Parameters ​

provide ​

Type<T>

The class to provide (used as both token and implementation)

options? ​

Configuration object

deps? ​

any[]

Optional array of dependencies to inject into the class constructor

multi? ​

boolean

Optional flag to enable multi-provider

Returns ​

ConstructorProvider

A type-safe ConstructorProvider object

Example ​

typescript
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { provideType } from '@dasch-ng/utils';

@Injectable()
class UserService {
  constructor(private http: HttpClient) {}
}

// Explicit dependency declaration (useful for custom injection scenarios)
provideType(UserService, { deps: [HttpClient] });

// Equivalent to just providing the class directly:
// { provide: UserService }

See ​

https://angular.dev/guide/di/dependency-injection-providers

Released under the MIT License.