Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit 4224266

Browse files
committed
Aggiunti metodi statici per Scrutor
1 parent 51f6da3 commit 4224266

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
namespace NET6CustomLibrary.Scrutor;
2+
3+
public static class ScrutorService
4+
{
5+
public static IServiceCollection AddRegisterTransientService<TAssembly>(this IServiceCollection services, string stringEndsWith) where TAssembly : class
6+
{
7+
services.Scan(scan =>
8+
scan.FromAssemblyOf<TAssembly>()
9+
.AddClasses(classes => classes.Where(type => type.Name.EndsWith(stringEndsWith)))
10+
.AsImplementedInterfaces()
11+
.WithTransientLifetime());
12+
13+
return services;
14+
}
15+
16+
public static IServiceCollection AddRegisterSingletonService<TAssembly>(this IServiceCollection services, string stringEndsWith) where TAssembly : class
17+
{
18+
services.Scan(scan =>
19+
scan.FromAssemblyOf<TAssembly>()
20+
.AddClasses(classes => classes.Where(type => type.Name.EndsWith(stringEndsWith)))
21+
.AsImplementedInterfaces()
22+
.WithSingletonLifetime());
23+
24+
return services;
25+
}
26+
27+
public static IServiceCollection AddRegisterScopedService<TAssembly>(this IServiceCollection services, string stringEndsWith) where TAssembly : class
28+
{
29+
services.Scan(scan =>
30+
scan.FromAssemblyOf<TAssembly>()
31+
.AddClasses(classes => classes.Where(type => type.Name.EndsWith(stringEndsWith)))
32+
.AsImplementedInterfaces()
33+
.WithScopedLifetime());
34+
35+
return services;
36+
}
37+
}

0 commit comments

Comments
 (0)