Skip to content

Commit 10c8a1c

Browse files
committed
refactor: migrate to non-constructor based dependency injection
1 parent 09b329b commit 10c8a1c

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

projects/ngx-sentry/src/lib/sentry.handler.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable, Inject, ErrorHandler } from '@angular/core'
1+
import { Injectable, ErrorHandler, inject } from '@angular/core'
22
import { captureException } from '@sentry/browser'
33
import { SentryOptions, OPTIONS } from './tokens'
44

@@ -9,12 +9,7 @@ import { SentryOptions, OPTIONS } from './tokens'
99
providedIn: 'root',
1010
})
1111
export class SentryErrorHandler implements ErrorHandler {
12-
/**
13-
* Initializes the sentry connected error handler.
14-
*
15-
* @param - The module options.
16-
*/
17-
public constructor(@Inject(OPTIONS) private readonly options: SentryOptions) {}
12+
private readonly options: SentryOptions = inject<SentryOptions>(OPTIONS)
1813

1914
/**
2015
* Handles any errors.

projects/ngx-sentry/src/lib/sentry.interceptor.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable, Inject } from '@angular/core'
1+
import { Injectable, inject } from '@angular/core'
22
import {
33
HttpInterceptor,
44
HttpRequest,
@@ -16,12 +16,7 @@ import { SentryOptions, OPTIONS } from './tokens'
1616
*/
1717
@Injectable()
1818
export class SentryErrorInterceptor implements HttpInterceptor {
19-
/**
20-
* Initializes the sentry connected HTTP interceptor.
21-
*
22-
* @param - The module options.
23-
*/
24-
public constructor(@Inject(OPTIONS) private readonly options: SentryOptions) {}
19+
private readonly options: SentryOptions = inject<SentryOptions>(OPTIONS)
2520

2621
/**
2722
* Intercepts HTTP requests and handles any HTTP errors.

src/app/app.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Component } from '@angular/core'
1+
import { Component, inject } from '@angular/core'
22
import { SentryService } from '@pascaliske/ngx-sentry'
33

44
@Component({
55
selector: 'cmp-root',
66
templateUrl: './app.component.html',
77
})
88
export class AppComponent {
9-
public constructor(private readonly sentryService: SentryService) {}
9+
private readonly sentryService: SentryService = inject(SentryService)
1010

1111
public trigger(): void {
1212
this.sentryService.captureException(new Error('DEMO!'))

0 commit comments

Comments
 (0)