-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathIServiceCollectionExtension.cs
More file actions
33 lines (31 loc) · 1.64 KB
/
Copy pathIServiceCollectionExtension.cs
File metadata and controls
33 lines (31 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System.IO.Abstractions;
using Microsoft.Extensions.DependencyInjection;
using PlcInterface.Ads.TwinCATAbstractions;
namespace PlcInterface.Ads;
/// <summary>
/// Extension methods for <see cref="IServiceCollection"/>.
/// </summary>
public static class IServiceCollectionExtension
{
/// <summary>
/// Configure the <see cref="IServiceCollection"/> for this PLC.
/// </summary>
/// <param name="serviceDescriptors">
/// The <see cref="IServiceCollection"/> to add the services to.
/// </param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IServiceCollection AddAdsPLC(this IServiceCollection serviceDescriptors)
=> serviceDescriptors
.AddSingletonFactory<ReadWrite, IReadWrite, IAdsReadWrite>()
.AddSingletonFactory<Monitor, IMonitor, IAdsMonitor>()
.AddSingletonFactory<SymbolHandler, ISymbolHandler, IAdsSymbolHandler>()
.AddSingletonFactory<PlcConnection, IPlcConnection<TwinCAT.Ads.IAdsConnection>, IAdsPlcConnection>()
.AddSingleton<IPlcConnection>(x => x.GetRequiredService<IAdsPlcConnection>())
.AddTransient<IAdsTypeConverter, AdsTypeConverter>()
.AddSingleton<TwinCAT.Ads.IAdsDisposableConnection, TwinCAT.Ads.AdsClient>()
.AddSingleton<IFileSystem, FileSystem>()
.AddSingleton<ISymbolLoaderFactory, SymbolLoaderFactoryAbstraction>()
.AddSingleton<ISumSymbolFactory, SumSymbolFactory>()
.ConfigureOptions<DefaultAdsPlcConnectionConfigureOptions>()
.ConfigureOptions<DefaultAdsSymbolHandlerSettingsConfigureOptions>();
}