|
7 | 7 | _IDisposable abstract class wrapper_ |
8 | 8 |
|
9 | 9 |
|
| 10 | +## Methods |
10 | 11 |
|
| 12 | +### AddServicesFromAssemblies(IServiceCollection services, Action<OltScrutorScanBuilder> action) |
| 13 | + |
| 14 | +Scans for services implementing `IOltInjectableScoped`, `IOltInjectableSingleton`, and `IOltInjectableTransient` interfaces and registers them with the provided `IServiceCollection`. |
| 15 | + |
| 16 | +#### Parameters |
| 17 | +- `services` (`IServiceCollection`): The service collection to add the services to. |
| 18 | +- `action` (`Action<OltScrutorScanBuilder>`): An action to configure the `OltScrutorScanBuilder`. |
| 19 | + |
| 20 | +#### Returns |
| 21 | +- `IServiceCollection`: The service collection with the added services. |
| 22 | + |
| 23 | +### AddServicesFromAssemblies<TBuilder>(TBuilder builder, Action<OltScrutorScanBuilder> action) where TBuilder : IOltHostBuilder |
| 24 | + |
| 25 | +Scans assemblies and registers services with the specified `IOltHostBuilder`. |
| 26 | + |
| 27 | +#### Parameters |
| 28 | +- `builder` (`TBuilder`): The host builder to add the services to. |
| 29 | +- `action` (`Action<OltScrutorScanBuilder>`): An action to configure the `OltScrutorScanBuilder`. |
| 30 | + |
| 31 | +#### Returns |
| 32 | +- `TBuilder`: The host builder with the added services. |
| 33 | + |
| 34 | +## Usage |
| 35 | + |
| 36 | +To use the `OltDependencyInjectionExtensions` class, you need to call the `AddServicesFromAssemblies` method on your `IServiceCollection` or `IOltHostBuilder` instance, passing in an action to configure the `OltScrutorScanBuilder`. |
| 37 | + |
| 38 | +### Example |
| 39 | +```csharp |
| 40 | + |
| 41 | +using Microsoft.Extensions.DependencyInjection; |
| 42 | +using OLT.Core; |
| 43 | + |
| 44 | +public class Startup |
| 45 | +{ |
| 46 | + public void ConfigureServices(IServiceCollection services) |
| 47 | + { |
| 48 | + services.AddServicesFromAssemblies(scan => scan.IncludeAssembly(typeof(SomeTypeInYourAssembly).Assembly)); |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +``` |
| 53 | + |
| 54 | +In this example, the `AddServicesFromAssemblies` method is used to scan and register services from the specified assembly. |
| 55 | + |
| 56 | +## Remarks |
| 57 | + |
| 58 | +- The `OltDependencyInjectionExtensions` class relies on the Scutor library to perform the scanning and registration of services. |
| 59 | +- The `OltScrutorScanBuilder` class is used to configure the scanning process, including specifying which assemblies to scan. |
| 60 | + |
| 61 | +For more information on the Scutor library, refer to the [Scutor documentation](https://github.com/khellang/Scrutor). |
| 62 | + |
| 63 | + |
| 64 | +### Example Using OltAssemblyScanBuilder |
| 65 | + |
| 66 | +```csharp |
| 67 | +using OLT.Core; |
| 68 | + |
| 69 | +var assemblies = new OltAssemblyScanBuilder() |
| 70 | + .IncludeFilter("OLT.", "MyApp.") |
| 71 | + .IncludeAssembly(typeof(LocalServiceCollectionExtenstions).Assembly, typeof(AnotherClassName).Assembly, typeof(IAppInterfaceHere).Assembly) |
| 72 | + .ExcludeMicrosoft() |
| 73 | + .ExcludeAutomapper() |
| 74 | + .DeepScan() |
| 75 | + .Build(); |
| 76 | + |
| 77 | +services.AddServicesFromAssemblies(builder => builder.IncludeAssemblies(assemblies)) |
| 78 | + .AddAppCors() |
| 79 | + .AddScoped<IAppIdentity, AppIdentity>() |
| 80 | + .AddScoped<IOltIdentity>(x => x.GetRequiredService<IAppIdentity>()) |
| 81 | + .AddScoped<IOltDbAuditUser>(x => x.GetRequiredService<IAppIdentity>()) |
| 82 | + .AddHttpContextAccessor(); |
| 83 | + |
| 84 | +``` |
| 85 | + |
| 86 | +For more information on the OltAssemblyScanBuilder library, refer to the [Documentation](https://github.com/OuterlimitsTech/olt-dotnet-utility-libraries/blob/b800cc75911f83332a98e07b5224c86d1ec1066b/src/OLT.Utility.AssemblyScanner/README.md). |
0 commit comments