public IocProvider()
        {
            var ioc = new SimpleInjectorContainer();

            ioc.InternalContainer.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

            ioc
            .Register(new IocDataAccessModule())
            .Register(new IocServicesModule());

            ioc.Register <IConfigurationProvider, IntegrationTestConfigurationProvider>(IocLifetimeEnum.Singleton);
            ioc.Register <ICurrentUserService, MockCurrentUserService>(IocLifetimeEnum.Scoped);
            ioc.Register <IMailService, DebugMailService>(IocLifetimeEnum.Singleton);

            _siContainer = ioc;
        }
        private static void InitializeContainer(Container container)
        {
            // For instance:
            //container.Register<IClienteAppService, ClienteAppService>(Lifestyle.Scoped);

            SimpleInjectorContainer.Register(container);
        }
Beispiel #3
0
        public static void Initialize()
        {
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();
            SimpleInjectorContainer.Register(container);
            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
            container.Verify();
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
Beispiel #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var appSettings = new ConfigurationBuilder()
                              .SetBasePath(Directory.GetCurrentDirectory())
                              .AddJsonFile("appsettings.json");

            IConfigurationRoot Configuration = appSettings.Build();

            var builder          = new DbContextOptionsBuilder <RestaurantContext>();
            var connectionString = Configuration["ConnectionStrings:DefaultConnection"];

            builder.UseMySql(connectionString);
            services.AddMvc();
            services.AddDbContext <RestaurantContext>(x => x.UseMySql(connectionString));

            container = SimpleInjectorContainer.Register(builder.Options);
            IntegrateSimpleInjector(services);

            services.AddMvc();

            // Configurando o serviço de documentação do Swagger
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1",
                             new Info
                {
                    Title       = "Restaurant",
                    Version     = "v1",
                    Description = "Api to list, insert, update and delete restaurants and dishes",
                    Contact     = new Contact
                    {
                        Name = "Paulo Vieira",
                        Url  = "https://github.com/paulohvieirajr"
                    }
                });

                string caminhoAplicacao =
                    PlatformServices.Default.Application.ApplicationBasePath;
                string nomeAplicacao =
                    PlatformServices.Default.Application.ApplicationName;
                string caminhoXmlDoc =
                    Path.Combine(caminhoAplicacao, $"{nomeAplicacao}.xml");

                c.IncludeXmlComments(caminhoXmlDoc);
            });

            services.AddCors(o => o.AddPolicy("CorsPolicy", X =>
            {
                X.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
            }));
        }
        private static void ConfigureIoc()
        {
            var ioc = new SimpleInjectorContainer();

            // Need to explicitly specify default scope
            ioc.InternalContainer.Options.DefaultScopedLifestyle = new WebRequestLifestyle();

            ioc
            .Register(new IocDataAccessModule())
            .Register(new IocServicesModule())
            .Register(new IocUiModule());

            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(ioc.InternalContainer));

            // Need for Simple Injector invoking on Web Api controller constructor call
            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(ioc.InternalContainer);
        }
Beispiel #6
0
        /// <summary>
        /// Integrates SimpleInjector
        /// </summary>
        /// <param name="services">Interface <see cref="IServiceCollection"/></param>
        private static void IntegrateSimpleInjector(IServiceCollection services)
        {
            var ioc = new SimpleInjectorContainer();

            ioc.InternalContainer.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();

            ioc
            .Register(new IocDataAccessModule())
            .Register(new IocServicesModule())
            .Register(new IocCoreUIModule());

            ioc.InternalContainer.Verify();

            GlobalConfiguration.Configuration.DependencyResolver =
                new SimpleInjectorWebApiDependencyResolver(ioc.InternalContainer);

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddSingleton <IControllerActivator>(
                new SimpleInjectorControllerActivator(ioc.InternalContainer));

            services.EnableSimpleInjectorCrossWiring(ioc.InternalContainer);
            services.UseSimpleInjectorAspNetRequestScoping(ioc.InternalContainer);
        }
Beispiel #7
0
 private static void InitializeContainer(Container container)
 {
     SimpleInjectorContainer.Register(container);
 }
Beispiel #8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var appSettings = new ConfigurationBuilder()
                              .SetBasePath(Directory.GetCurrentDirectory())
                              .AddJsonFile("appsettings.json");

            IConfigurationRoot Configuration = appSettings.Build();

            var builder          = new DbContextOptionsBuilder <CestechContext>();
            var connectionString = Configuration["ConnectionStrings:DefaultConnection"];

            builder.UseMySql(connectionString);
            services.AddMvc();
            services.AddDbContext <CestechContext>(x => x.UseMySql(connectionString));

            container = SimpleInjectorContainer.Register(builder.Options);
            IntegrateSimpleInjector(services);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(option =>
            {
                option.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,

                    ValidIssuer      = "Securiry.Bearer",
                    ValidAudience    = "Securiry.Bearer",
                    IssuerSigningKey = ProviderJWT.JWTSecurityKey.Create("Secret_Key-Cestech")
                };

                option.Events = new JwtBearerEvents
                {
                    OnAuthenticationFailed = context =>
                    {
                        Console.WriteLine("OnAuthenticationFailed: " + context.Exception.Message);
                        return(Task.CompletedTask);
                    },
                    OnTokenValidated = context =>
                    {
                        Console.WriteLine("OnTokenValidated: " + context.SecurityToken);
                        return(Task.CompletedTask);
                    }
                };
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("UsuarioApi",
                                  policy => policy.RequireClaim("UsuarioAPI"));
            });

            services.AddMvc();

            // Configurando o serviço de documentação do Swagger
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1",
                             new Info
                {
                    Title       = "Cestech",
                    Version     = "v1",
                    Description = "Api base Cestech",
                    Contact     = new Contact
                    {
                        Name = "Wodson Luiz",
                        Url  = "https://github.com/wodsonluiz"
                    }
                });

                string caminhoAplicacao =
                    PlatformServices.Default.Application.ApplicationBasePath;
                string nomeAplicacao =
                    PlatformServices.Default.Application.ApplicationName;
                string caminhoXmlDoc =
                    Path.Combine(caminhoAplicacao, $"{nomeAplicacao}.xml");

                c.IncludeXmlComments(caminhoXmlDoc);
            });

            services.AddCors(o => o.AddPolicy("CorsPolicy", X =>
            {
                X.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
            }));
        }