protected override void ConfigureWebHost(IWebHostBuilder webhostBuilder)
        {
            webhostBuilder
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseDefaultServiceProvider(p => p.ValidateScopes = true)
            .ConfigureServices((context, services) =>
            {
#if NETCOREAPP3_0
                services.AddControllers();
#else
                services.AddMvc();
#endif
                AdditionalServices?.Invoke(services);
            })
            .ConfigureLogging(l =>
            {
                l.SetMinimumLevel(LogLevel.Debug);
                l.AddFilter("Microsoft", LogLevel.Warning);
                l.AddProvider(_loggerProvider);
            })
            .Configure(appBuilder =>
            {
#if NETCOREAPP3_0
                appBuilder.UseRouting();
                appBuilder.UseEndpoints(config =>
                {
                    config.MapControllers();
                });
#else
                appBuilder.UseMvc();
#endif
            });
        }
Ejemplo n.º 2
0
        protected override void ConfigureWebHost(IWebHostBuilder builder)
        {
            builder
            .UseEnvironment("BuildTest")
            .UseDefaultServiceProvider(p => p.ValidateScopes = true)
            .ConfigureServices((context, services) =>
            {
                // configure our petstore with a unique host so that we can mock it using different urls than other services we might want to mock
                services.PostConfigure <PetStoreOptions>(o =>
                {
                    o.Url = "http://petstore";
                });

                // since we registered with a named client, we can configure it so that we can mock all the requests and responses
                services.AddHttpClient(PetStoreOptions.HttpClientName).ConfigurePrimaryHttpMessageHandler(() => PetStoreMockHandler);

                AdditionalServices?.Invoke(context, services);
            })
            .ConfigureAppConfiguration((context, configurationBuilder) =>
            {
                AdditionalConfiguration?.Invoke(context, configurationBuilder);
            })
            .ConfigureLogging((context, builder) =>
            {
                builder.ClearProviders();
                // values are picked up from appsetting.json
                builder.AddProvider(_loggerProvider);

                // log level cannot be modified here since this is triggered after the configuration settings have been established
                // need to make changes in the AdditionalConfiguration since that happens earlier in the lifecycle
                AdditionalLogging?.Invoke(context, builder);
            });
        }
        private static void PrepareServices(IServiceCollection serviceCollection, StartupMethods startupMethods)
        {
            if (startupMethods?.ConfigureServicesDelegate != null)
            {
                startupMethods.ConfigureServicesDelegate(serviceCollection);
            }
            else
            {
                var defaultRegistrationPlugin = DefaultRegistrationPlugins
                                                .OrderByDescending(p => p.Priority)
                                                .FirstOrDefault();

                if (defaultRegistrationPlugin != null)
                {
                    defaultRegistrationPlugin.DefaultServiceRegistrationDelegate(serviceCollection);
                }
                else
                {
                    serviceCollection
                    .AddMvcCore()
                    .AddFormatterMappings()
                    .AddJsonFormatters();
                }
            }

            AdditionalServices?.Invoke(serviceCollection);

            // custom MVC options
            serviceCollection.Configure <MvcOptions>(options =>
            {
                // add controller conventions to save all valid controller types
                options.Conventions.Add(new ValidControllersCache());

                // string input formatter helps with HTTP request processing
                var inputFormatters = options.InputFormatters.OfType <TextInputFormatter>();
                if (!inputFormatters.Any(f => f.SupportedMediaTypes.Contains(ContentType.TextPlain)))
                {
                    options.InputFormatters.Add(new StringInputFormatter());
                }
            });

            TryReplaceKnownServices(serviceCollection);
            PrepareRouteServices(serviceCollection);

            serviceProvider = serviceCollection.BuildServiceProvider();

            // this call prepares all application conventions and fills the controller action descriptor cache
            serviceProvider.GetService <IControllerActionDescriptorCache>();
        }
        private static void PrepareServices(IServiceCollection serviceCollection, StartupMethods startupMethods)
        {
            if (startupMethods?.ConfigureServicesDelegate != null)
            {
                startupMethods.ConfigureServicesDelegate(serviceCollection);
            }
            else
            {
                var defaultRegistrationPlugin = DefaultRegistrationPlugins
                                                .OrderByDescending(p => p.Priority)
                                                .FirstOrDefault();

                if (defaultRegistrationPlugin != null)
                {
                    defaultRegistrationPlugin.DefaultServiceRegistrationDelegate(serviceCollection);
                }
                else
                {
                    serviceCollection.AddMvcCore();
                }
            }

            AdditionalServices?.Invoke(serviceCollection);

            TryReplaceKnownServices(serviceCollection);
            PrepareRoutingServices(serviceCollection);

#if NET451
            var baseStartupType = StartupType;
            while (baseStartupType != null && baseStartupType?.BaseType != typeof(object))
            {
                baseStartupType = baseStartupType.BaseType;
            }

            var applicationPartManager = (ApplicationPartManager)serviceCollection
                                         .FirstOrDefault(t => t.ServiceType == typeof(ApplicationPartManager))
                                         ?.ImplementationInstance;

            if (applicationPartManager != null && baseStartupType != null)
            {
                applicationPartManager.ApplicationParts.Add(new AssemblyPart(baseStartupType.GetTypeInfo().Assembly));
            }
#endif

            serviceProvider = serviceCollection.BuildServiceProvider();

            InitializationPlugins.ForEach(plugin => plugin.InitializationDelegate(serviceProvider));
        }
Ejemplo n.º 5
0
 private void AddFinallyBtn_Click(object sender, RoutedEventArgs e)
 {
     if (!string.IsNullOrEmpty(ServicesNameTb.Text) && !string.IsNullOrEmpty(ServicesPriceTb.Text))
     {
         NewServices = new AdditionalServices
         {
             Name  = ServicesNameTb.Text,
             Price = float.Parse(ServicesPriceTb.Text)
         };
     }
     else
     {
         return;
     }
     ServicesRep.Add(NewServices);
     Close();
 }
Ejemplo n.º 6
0
        public T GetService <T>()
        {
            if (_serviceProvider == null)
            {
                // add standard services
                _serviceCollection.AddOptions();
                _serviceCollection.AddLogging(setup => setup.AddProvider(_loggerProvider));
                _serviceCollection.AddSingleton <IConfiguration>(Configuration);

                // allow test to customize services
                AdditionalServices?.Invoke(_serviceCollection, Configuration);

                _serviceProvider = _serviceCollection.BuildServiceProvider();
            }

            return(_serviceProvider.GetRequiredService <T>());
        }
Ejemplo n.º 7
0
        private async void BindProperties(Vouchers voucher)
        {
            if (voucher != null)
            {
                Voucher = voucher;
            }

            Clients = await GetClients();

            Hotels = await GetHotels();

            RestTypes = await GetRestTypes();

            AdditionalServices = await GetAdditionalServices();

            Stuffs = await GetStuffs();

            PaymentStatuses = new List <string> {
                "Оплачено", "Не оплачено"
            };
            BookingStatuses = new List <string> {
                "Забронирован", "Не забронирован"
            };

            if (_handleType == HandleType.Add)
            {
                return;
            }
            Client        = Clients.FirstOrDefault(p => Voucher.ClientId == p.Id);
            Hotel         = Hotels.FirstOrDefault(p => Voucher.HotelId == p.Id);
            RestType      = RestTypes.FirstOrDefault(p => Voucher.RestTypeId == p.Id);
            Stuff         = Stuffs.FirstOrDefault(p => Voucher.StuffId == p.Id);
            PaymentStatus = Voucher.PaymentStatus;
            BookingStatus = Voucher.BookingStatus;
            StartDate     = Voucher.StartDate;
            EndDate       = Voucher.EndDate;

            AdditionalService1 = AdditionalServices.FirstOrDefault(p => Voucher.AdditService1Id == p.Id);
            AdditionalService2 = AdditionalServices.FirstOrDefault(p => Voucher.AdditService2Id == p.Id);
            AdditionalService3 = AdditionalServices.FirstOrDefault(p => Voucher.AdditService3Id == p.Id);
        }
Ejemplo n.º 8
0
        private void FillWithData()
        {
            foreach (var item in new UserDAO().GetAll())
            {
                Users.Add(item);
            }


            foreach (var item in new SaleDAO().GetAll())
            {
                Sales.Add(item);
            }


            foreach (var item in new FurnitureTypeDAO().GetAll())
            {
                FurnitureTypes.Add(item);
            }


            foreach (var item in new FurnitureDAO().GetAll())
            {
                Furniture.Add(item);
            }


            foreach (var item in new AdditionalServiceDAO().GetAll())
            {
                AdditionalServices.Add(item);
            }

            foreach (var item in new ActionSaleDAO().GetAll())
            {
                ActionSales.Add(item);
            }
        }