private void ValidateConnection(CdsServiceClient client) { // Validate it var rslt = client.Execute(new WhoAmIRequest()); Assert.IsType <WhoAmIResponse>(rslt); // Clone it. - Validate use using (CdsServiceClient client2 = client.Clone()) { rslt = client2.Execute(new WhoAmIRequest()); Assert.IsType <WhoAmIResponse>(rslt); } // Create clone chain an break linkage. CdsServiceClient client3 = client.Clone(); CdsServiceClient client4 = client3.Clone(); rslt = client3.Execute(new WhoAmIRequest()); Assert.IsType <WhoAmIResponse>(rslt); // dispose client3 explicitly client3.Dispose(); rslt = client4.Execute(new WhoAmIRequest()); Assert.IsType <WhoAmIResponse>(rslt); client4.Dispose(); }
public CdsServiceClient Rent() { if (_disposed) { throw new ObjectDisposedException(nameof(CdsServiceClientPool)); } if (_pool.TryDequeue(out var client)) { Interlocked.Decrement(ref _count); return(client); } if (_defaultClient.IsReady) { _logger.LogInformation("Cloning CdsServiceClient"); var svcClientClone = _defaultClient.Clone(); svcClientClone.SessionTrackingId = Guid.NewGuid(); return(svcClientClone); } _logger.LogError(_defaultClient.LastCdsException, $"CdsServiceClient is 'Not Ready'. Reason: {_defaultClient.LastCdsError}"); throw new Exception($"CdsServiceClient is 'Not Ready'. Reason: {_defaultClient.LastCdsError}", _defaultClient.LastCdsException); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers() .AddJsonOptions(x => { x.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); }) .AddNewtonsoftJson(o => { o.SerializerSettings.TypeNameHandling = TypeNameHandling.Auto; }); services.AddSwaggerGen(c => { c.SwaggerDoc( "v1", new OpenApiInfo { Title = "Review school and college data API - V1", Version = "V1", Description = "Provides a restful API for intergating with the RSCD Dynamics CRM Common Data Service and CosmosDB data sources", License = new OpenApiLicense { Name = "MIT License", Url = new Uri("https://opensource.org/licenses/MIT") } }); c.EnableAnnotations(); c.UseAllOfToExtendReferenceSchemas(); }); // Adds feature management for Azure App Configuration services.AddFeatureManagement(); services.AddAzureAppConfiguration(); if (!_env.IsProduction()) { // obtain CRM request messages in non-prod environments services.AddSingleton <ITelemetryInitializer, CrmTelemetryInitializer>(); } services.AddApplicationInsightsTelemetry(); var referenceDataConnectionString = Configuration.GetConnectionString("ReferenceData"); services.AddDbContext <SqlDataRepositoryContext>(options => options.UseSqlServer( referenceDataConnectionString, providerOptions => providerOptions.EnableRetryOnFailure())); services.AddScoped <IDataRepository, DataRepository>(); services.AddScoped <IDataService, DataService>(); // Dynamics 365 configuration var dynamicsConnString = Configuration.GetConnectionString("DynamicsCds"); var cdsClient = new CdsServiceClient(dynamicsConnString); services.AddTransient <IOrganizationService, CdsServiceClient>(sp => cdsClient.Clone()); // Microsoft Extensions Configuration (services.Configure) is still in Alpha. // This affects EntityFramework Core in Infra Assembly // So we do it the old fashioned way for now var dynamicsOptions = Configuration.GetSection("Dynamics").Get <DynamicsOptions>(); services.AddSingleton(dynamicsOptions); services.AddSingleton <IAllocationYearConfig>(new AllocationYearConfig { Value = Configuration["AllocationYear"], CensusDate = Configuration["AnnualCensusDate"] }); if (!_env.IsEnvironment(Program.LOCAL_ENVIRONMENT)) { services.Configure <BasicAuthOptions>(Configuration.GetSection("BasicAuth")); } ; // Microsoft Extensions Configuration (services.Configure) is still in Alpha. // This affects EntityFramework Core in Infra Assembly // So we do it the old fashioned way for now var cosmosDbOptions = Configuration.GetSection("CosmosDb").Get <CosmosDbOptions>(); services.AddSingleton(cosmosDbOptions); services.AddSingleton <IDocumentRepository, CosmosDocumentRepository>(); services.AddScoped <IRule, RemovePupilAdmittedFromAbroadRule>(); services.AddScoped <IRule, RemovePupilAdmittedFollowingPermanentExclusion>(); services.AddScoped <IRule, RemovePupilDeceased>(); services.AddScoped <IRule, RemovePupilPermanentlyLeftEngland>(); services.AddScoped <IRule, RemovePupilDualRegistration>(); services.AddScoped <IRule, RemovePupilOtherTerminalLongIllnessRule>(); services.AddScoped <IRule, RemovePupilOtherPoliceInvolvementBailRule>(); services.AddScoped <IRule, RemovePupilOtherSafeguardingFapRule>(); services.AddScoped <IRule, RemovePupilOtherInPrisonRemandCentreSecureUnitRule>(); services.AddScoped <IRule, RemovePupilOtherPermanentlyExcluded>(); services.AddScoped <IRule, RemovePupilOtherElectiveHomeEducationRule>(); services.AddScoped <IRule, RemovePupilOtherMissingInEducation>(); services.AddScoped <IRule, RemovePupilOtherEalExceptionalCircumstances>(); services.AddScoped <IAmendmentBuilder, RemovePupilAmendmentBuilder>(); services.AddScoped <Amendment, RemovePupilAmendment>(); services.AddScoped <IEstablishmentService, EstablishmentService>(); services.AddScoped <IPupilService, PupilService>(); services.AddScoped <IAmendmentService, CrmAmendmentService>(); services.AddScoped <IOutcomeService, OutcomeService>(); services.AddScoped <IConfirmationService, CrmConfirmationService>(); }