AzureCosmosFactoryExtensions.cs 843 B

1234567891011121314151617181920
  1. using Microsoft.Extensions.DependencyInjection;
  2. using Microsoft.Extensions.DependencyInjection.Extensions;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace TEAMModelOS.SDK.DI
  7. {
  8. public static class AzureCosmosFactoryExtensions
  9. {
  10. public static IServiceCollection AddAzureCosmos(this IServiceCollection services, string connectionString, string name = "Default")
  11. {
  12. if (services == null) throw new ArgumentNullException(nameof(services));
  13. if (connectionString == null) throw new ArgumentNullException(nameof(connectionString));
  14. services.TryAddSingleton<AzureCosmosFactory>();
  15. services.Configure<AzureCosmosFactoryOptions>(name, o => { o.Name = name; o.CosmosConnectionString = connectionString; });
  16. return services;
  17. }
  18. }
  19. }