Esempio n. 1
0
        /// <summary>
        /// Create Autofac Service Provider
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        private static void CreateAutofacServiceProvider(IServiceCollection services, string connectionString)
        {
            DependencyResolver.AddModules(services, new DataModule().Bindings.ToList());
            DependencyResolver.AddModules(services, new ServicesModule().Bindings.ToList());


            services.AddTransient(x => new AppointmentsDbContext(new DbContextOptionsBuilder <AppointmentsDbContext>().UseSqlServer(connectionString).Options));
            services.AddTransient <ISqlConnectionManager>(x => new SqlConnectionManager(connectionString));

            services.AddMediatR(new Assembly[] { typeof(Patient).GetTypeInfo().Assembly, typeof(AppointmentNotification).GetTypeInfo().Assembly });

            services.AddProblemDetails(x =>
            {
                x.Map <InvalidCommandException>(ex => new InvalidCommandProblemDetails(ex));
                x.Map <BusinessRuleViolationException>(ex => new BusinessRuleViolationExceptionProblemDetails(ex));
            });
        }