예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddResponseCaching();

            services.AddControllers(options =>
            {
                options.ReturnHttpNotAcceptable = true;

                options.Filters.Add <ValidationFilter>();
                options.Filters.Add <ApiExceptionAttribute>();
                options.Filters.Add(new ProducesAttribute("application/json", "application/xml", "application/vnd.marvin.hateoas+json"));
                options.Filters.Add(new ConsumesAttribute("application/json", "application/xml"));
            })
            .AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                options.SerializerSettings.NullValueHandling     = NullValueHandling.Ignore;
            })
            .AddFluentValidation(fvc => fvc.RegisterValidatorsFromAssemblyContaining <Startup>())
            .AddXmlDataContractSerializerFormatters();

            services.AddSwaggerGen(c =>
            {
                c.ExampleFilters();

                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);

                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "eMobile.Phones.API", Version = "v1"
                });
            })
            .AddSwaggerExamplesFromAssemblyOf <Startup>();

            services.AddAutoMapper(typeof(Startup));

            services.AddDbContext <PhonesContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")))
            .AddHealthChecks()
            .AddDbContextCheck <PhonesContext>(
                name: "PhonesContext",
                failureStatus: HealthStatus.Degraded,
                tags: new[] { "readiness" });

            services.AddHealthChecks()
            .AddCheck <StartupHostedServiceHealthCheck>(
                "StartupHostedServiceHealthCheck",
                failureStatus: HealthStatus.Degraded,
                tags: new[] { "liveness" });

            services.AddHostedService <StartupHostedService>();
            services.AddSingleton <StartupHostedServiceHealthCheck>();

            var container = new ContainerBuilder();

            IoCService.RegisterServices(container, services);
            container.Populate(services);

            return(new AutofacServiceProvider(container.Build()));
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddCors();
            //services.AddSwaggerGen(c =>
            //{
            //    c.SwaggerDoc("v1",
            //        new Info
            //        {
            //            Title = "AngelHack",
            //            Version = "v1",
            //            Description = "API da MeLevaPraCasa - AngelHack",
            //            Contact = new Contact
            //            {
            //                Name = "MeLevaPraCasa",
            //                Url = "https://github.com/Bruini/MeLevaPraCasa"
            //            }
            //        });

            //    // Usar a documentação XML dos métodos.

            //    var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
            //    var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
            //    c.IncludeXmlComments(xmlPath);


            //});

            var ioc = new IoCService();

            ioc.Register(services);
        }
예제 #3
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var container = new Container();

            IoCService.Register(container);
            //container.Register<IEducationPortalContext, DAL.Context.EducationPortalContext>(Lifestyle.Singleton);
            //container.Register<IEFRepository, DAL.Repository.Repository>(Lifestyle.Singleton);

            container.Register <IPasswordHasher, BL.Services.UserServices.PasswordHasherService>(Lifestyle.Singleton);
            container.Register <IUser, BL.Services.UserServices.UserService>(Lifestyle.Singleton);
            container.Register <ICourse, BL.Services.CourseServices.CourseService>(Lifestyle.Singleton);
            container.Register <IMaterial, BL.Services.MaterialServices.MaterialService>(Lifestyle.Singleton);
            container.Register <Core.Interfaces.ISkill, BL.Services.SkillService.SkillService>(Lifestyle.Singleton);

            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());

            container.Verify();

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
예제 #4
0
        private IPlaylistBottomBarViewModel GetPlaylistBottomBar()
        {
            var playlistBottomBarViewModel = IoCService.Get <IPlaylistBottomBarViewModel>();

            playlistBottomBarViewModel.OnPlaylistDeleted = async() => await Populate();

            return(playlistBottomBarViewModel);
        }
예제 #5
0
        public static void RegisterComponents()
        {
            var container = new UnityContainer();

            IoCService.RegisterTypes(container);

            // register all your components with the container here
            // it is NOT necessary to register your controllers

            // e.g. container.RegisterType<ITestService, TestService>();

            DependencyResolver.SetResolver(new UnityDependencyResolver(container));
        }
예제 #6
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            var         mainWindow = new MainWindow();
            IIoCService iocService = new IoCService
            {
                RegisterComponents = (ioc) =>
                {
                    ioc.RegisterType <ESPMessageService>().As <IESPMessageService>(true);
                    ioc.RegisterType <HTTPServer>().As <IHTTPServer>();
                }
            };

            iocService.Build();
            iocService.Resolve <IAppService>().SetTheme(ThemeType.Light);
            mainWindow.DataContext = iocService.Resolve <IMainWindowViewModel>();
            mainWindow.Show();

            iocService.Resolve <INavigationService>().NavigateTo <FindESPViewModel, FindESPView>();
        }
예제 #7
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            var window = new MainWindow();

            IIoCService iocService = new IoCService
            {
                RegisterComponents = (ioc) =>
                {
                    ioc.RegisterType <ESPMessageService>().As <IESPMessageService>();
                }
            };

            iocService.Build();
            iocService.Resolve <IAppService>().SetTheme(ThemeType.Light);
            window.DataContext = iocService.Resolve <IMainWindowViewModel>();
            window.Show();

            iocService.Resolve <INavigationService>().NavigateTo <FindESPViewModel, FindESPView>();

            AppDomain.CurrentDomain.UnhandledException += (s, e) => iocService.Resolve <IAppService>().ProcessException((Exception)e.ExceptionObject, "Domain exception");
            Dispatcher.UnhandledException += (s, e) =>
            {
                e.Handled = true;
                iocService.Resolve <IAppService>().ProcessException(e.Exception, "Dispatcher exception");
            };
            TaskScheduler.UnobservedTaskException += (s, e) =>
            {
                if (e.Exception != null)
                {
                    iocService.Resolve <IAppService>().ProcessException(e.Exception, "Unobserved exception");
                    e.SetObserved();
                }
            };
        }
예제 #8
0
 private void InstantiateRequiredSingletons()
 {
     IoCService.Get <IPlaybackViewModel>();
     IoCService.Get <INotificationsHelper>();
 }
예제 #9
0
 protected override void ConfigureContainer(ContainerBuilder builder)
 {
     IoCService.RegisterDependencies(builder);
     builder.RegisterBuildCallback(container =>
                                   IoCService.Instance = new IoCService(container));
 }
예제 #10
0
 protected override void RegisterTypes(IContainerRegistry containerRegistry)
 {
     IoCService.RegisterTypes(containerRegistry);
 }
 protected override void RegisterTypes(IContainerRegistry containerRegistry)
 {
     //Registering all the services
     IoCService.RegisterTypes(containerRegistry);
 }