예제 #1
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     RepositoryModule.Register(services, Configuration.GetConnectionString("DefaultConnection"), GetType().Assembly.FullName);
     ServicesModule.Register(services);
     services.AddMvc(option => option.EnableEndpointRouting = false).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
     //services.AddControllers();
 }
예제 #2
0
 public static void RegisterServices(this Container container)
 {
     UnitOfWorkModule.Register(container);
     ServicesModule.Register(container);
     RepositoryModule.Register(container);
     DbContextModule.Register(container);
 }
예제 #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <IDataSeed>(new DataSeed());
            RepositoryModule.Register(services,
                                      Configuration.GetConnectionString("DefaultConnection"),
                                      GetType().Assembly.FullName);
            ServicesModule.Register(services);

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "CrossOver API Documentation", Version = "v1", Description = "This API makes use of json response", Contact = new Contact()
                    {
                        Email = "*****@*****.**", Name = "Emad Hamdy"
                    }
                });
                //c.AddSecurityDefinition("Bearer", new ApiKeyScheme() { In = "header", Description = "Please insert JWT with Bearer into field", Name = "Authorization", Type = "apiKey" });
                //c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>>
                // {
                //        { "Bearer", new string[]{ } },
                //        { "Basic", new string[]{ } },
                //  });
                // Set the comments path for the Swagger JSON and UI.
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                var xmlPath  = Path.Combine(basePath, "XOProject.Api.xml");
                c.IncludeXmlComments(xmlPath);
            });
            services.AddMvc();
        }
예제 #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add GCConnection
            services.AddDbContext <WebAppDataContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")), ServiceLifetime.Scoped);

            services.AddScoped <DbContext>(provider => provider.GetService <WebAppDataContext>());
            services.AddMvcCore()
            .AddAuthorization()
            // .AddJsonFormatters()
            .AddApiExplorer();

            services.AddMvc(option => option.EnableEndpointRouting = false)
            .AddNewtonsoftJson();
            // Add cors
            services.AddCors();

            // Add Register modules.
            ServiceModule.Register(services, Configuration);
            RepositoryModule.Register(services);
            AutoMapperModule.Register(services);

            services.AddMvc();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "My API", Version = "v1"
                });
            });
        }
예제 #5
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddSwaggerGen(c =>
     {
         c.SwaggerDoc("v1", new Info {
             Title = "Hubtiger API Documentation", Version = "v1", Description = "this API makes use of JWT to access the Hubtiger API", Contact = new Contact()
             {
                 Email = "*****@*****.**"
             }
         });
         c.AddSecurityDefinition("Bearer", new ApiKeyScheme()
         {
             In = "header", Description = "Please insert JWT with Bearer into field", Name = "Authorization", Type = "apiKey"
         });
         c.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> >
         {
             { "Bearer", new string[] { } },
             { "Basic", new string[] { } },
         });
         // Set the comments path for the Swagger JSON and UI
         var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
         var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
         c.IncludeXmlComments(xmlPath);
     });
     RepositoryModule.Register(services, Configuration.GetConnectionString("azure"));
     ServiceModule.Register(services);
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
 }
예제 #6
0
        public static async void Start(DateTime dateStart, int bookingId)
        {
            ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
            var scheduler = schedulerFactory.GetScheduler().GetAwaiter().GetResult();

            var services = new ServiceCollection();

            services.AddTransient <IJobFactory, NinjectJobFactory>();
            services.AddScoped <IJob, RemoveBookingJob>();
            services.AddScoped <IBookingService, BookingService>();


            NinjectModule serviceModule = new ServiceModule("DefaultConnection");
            NinjectModule roomModule    = new RepositoryModule("DefaultConnection");
            var           kernel        = new StandardKernel(serviceModule, roomModule);

            var container  = services.BuildServiceProvider();
            var jobFactory = new NinjectJobFactory(kernel);

            scheduler.JobFactory = jobFactory;
            await scheduler.Start();


            var job        = JobBuilder.Create <RemoveBookingJob>().Build();
            var triggerKey = new TriggerKey(bookingId.ToString(), dateStart.ToShortDateString() + bookingId);
            var trigger    = TriggerBuilder.Create()
                             .WithIdentity(triggerKey)
                             .StartAt(dateStart.AddMinutes(1))
                             .UsingJobData("bookingId", bookingId)
                             .Build();

            await scheduler.ScheduleJob(job, trigger);
        }
예제 #7
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     RepositoryModule.Register(services, Configuration.GetConnectionString("DefaultConnection"), GetType().Assembly.FullName);
     ServicesModule.Register(services);
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
     services.AddCors();
 }
예제 #8
0
파일: Startup.cs 프로젝트: Karthickvr/test
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddSingleton <IDataSeed>(new DataSeed());
     RepositoryModule.Register(services,
                               Configuration.GetConnectionString("DefaultConnection"),
                               GetType().Assembly.FullName);
     ServicesModule.Register(services);
     services.AddMvc();
 }
예제 #9
0
 public void SetStatus(List <int> IDs)
 {
     foreach (var item in IDs)
     {
         var data = new RepositoryModule().Get(item);
         data.Status = !data.Status;
         new RepositoryModule().Update(data);
     }
 }
        public void Binds_ToDataService( )
        {
            var kernel = new StandardKernel( );

            var module = new RepositoryModule(service.Object);

            kernel.Load(module);

            Assert.AreSame(repository.Object, kernel.Get <IRepository <Object> >( ));
        }
예제 #11
0
 public void ConfigureServices(IServiceCollection services)
 {
     RepositoryModule.Register(services, Configuration.GetConnectionString("LocalConnection"));
     services.AddMvc().AddNewtonsoftJson();
     services.AddResponseCompression(opts =>
     {
         opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
             new[] { "application/octet-stream" });
     });
 }
        public bool Validate(string token, string URL, AuditAction action)
        {
            try
            {
                var  dataUsuario = new RepositoryUser().GetToken(token);
                var  dataPermiso = GetAll(dataUsuario.ProfileID);
                var  dataModulo  = new RepositoryModule().GetURL(URL);
                bool AllowAccess = false;

                switch (action)
                {
                case AuditAction.Access:
                    AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Access;
                    break;

                case AuditAction.Read:
                    AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Read;
                    break;

                case AuditAction.Add:
                    AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Add;
                    break;

                case AuditAction.Update:
                    AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Update;
                    break;

                case AuditAction.Delete:
                    AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Delete;
                    break;

                case AuditAction.Export:
                    AllowAccess = dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Export;
                    break;

                default:
                    AllowAccess = false;
                    break;
                }

                if (AllowAccess)
                {
                    new BusinessAudit().Insert(new ModelViewAudit()
                    {
                        ModuleID = dataModulo.ModuleID, UserID = dataUsuario.UserID, Action = action.ToString()
                    });
                }

                return(AllowAccess);
            }
            catch
            {
                return(true);
            }
        }
예제 #13
0
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);

            RepositoryModule.Initialize();
            CoreModule.Initialize();
            Net.Framework.Entity.IocInstaller.Init();
            //Net.General.Dependency.MVC.WindsorControllerFactory.Register(Assembly.GetExecutingAssembly());

            GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
        }
예제 #14
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     RepositoryModule.Register(services,
                               Configuration.GetConnectionString("DefaultConnection"),
                               GetType().Assembly.FullName);
     ServicesModule.Register(services);
     services.AddMvc(option => option.EnableEndpointRouting = false).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
     services.AddCors(allowsites => {
         allowsites.AddPolicy("AllowOrigin", options => options.AllowAnyOrigin());
     });
 }
예제 #15
0
 private static void InitializeContainer(Container container)
 {
     AppServiceModule.Register(container);
     ServiceModule.Register(container);
     RepositoryModule.Register(container);
     DataModule.Register(container);
     ValidatorModule.Register(container);
     //FluentValidationModelValidatorProvider.Configure(GlobalConfiguration.Configuration, provider =>
     //{
     //    provider.ValidatorFactory = new ApplicationValidatorFactory(container);
     //});
 }
 public bool Validate(string token, string URL)
 {
     try
     {
         var dataUsuario = new RepositoryUser().GetToken(token);
         var dataPermiso = GetAll(dataUsuario.ProfileID);
         var dataModulo  = new RepositoryModule().GetURL(URL);
         return(dataPermiso.Where(p => p.ModuleID == dataModulo.ModuleID).Single().Access);
     }
     catch
     {
         return(true);
     }
 }
예제 #17
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            //dependency injection
            NinjectModule serviceModule = new ServiceModule("DefaultConnection");
            NinjectModule roomModule    = new RepositoryModule("DefaultConnection");
            var           kernel        = new StandardKernel(serviceModule, roomModule);

            kernel.Unbind <ModelValidatorProvider>();
            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
            Logger.InitLogger(); //Logger initialization
        }
예제 #18
0
        public static Container RegisterServices(Assembly assembly)
        {
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();
            ApplicationModule applicationModule = new ApplicationModule();
            ServiceModule     serviceModule     = new ServiceModule();
            RepositoryModule  repositoryModule  = new RepositoryModule();

            applicationModule.Load(container);
            serviceModule.Load(container);
            repositoryModule.Load(container);
            container.RegisterMvcControllers(assembly);
            container.Verify();
            return(container);
        }
예제 #19
0
        public ModelViewModule Update(ModelViewModule model)
        {
            EntityModule data = new EntityModule()
            {
                ModuleID    = model.ModuleID,
                Module      = model.Module,
                Description = model.Description,
                Status      = model.Status,
                URL         = model.URL,
                Section     = model.Section
            };

            data           = new RepositoryModule().Update(data);
            model.ModuleID = data.ModuleID;

            return(model);
        }
예제 #20
0
        public void ConfigureServices(IServiceCollection services)
        {
            services
            .SwaggerConfigure()
            .AddCors()
            .AddOptions()
            .ConfigureContext(Configuration)
            .AddMvc(options => options.EnableEndpointRouting = false);

            services.AddScoped <IUnitOfWork, UnitOfWork>();

            services.Configure <DbProvider>(d =>
            {
                d.ToDo = Configuration.GetConnectionString("ToDo");
            });

            RepositoryModule.Configure(services);
            ServiceModule.Configure(services);
            DapperModule.Configure(services);
        }
예제 #21
0
        private void InitializeContainer()
        {
            container = new Container();

            var mixed = Lifestyle.CreateHybrid(new AsyncScopedLifestyle(), new ThreadScopedLifestyle());
            var style = Lifestyle.CreateHybrid(new WebRequestLifestyle(), mixed);

            container.Options.DefaultScopedLifestyle = style;

            RepositoryModule.Initialize(container);
            ServiceModule.Initialize(container);
            FactoryModule.Initialize(container);

            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);
            container.RegisterInjections();
            container.Verify();

            GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
        }
예제 #22
0
        public ModelViewModule Insert(ModelViewModule model)
        {
            model.Status = true;

            EntityModule data = new EntityModule()
            {
                ModuleID    = model.ModuleID,
                Module      = model.Module,
                Description = model.Description,
                Status      = model.Status,
                URL         = model.URL,
                Section     = model.Section
            };

            data           = new RepositoryModule().Insert(data);
            model.ModuleID = data.ModuleID;

            new BusinessPermission().Set(null, model.ModuleID);

            return(model);
        }
예제 #23
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
            var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);

            SwaggerServiceModule.Register(services, new SwaggerIntegrationHelper
            {
                Description = "Account Microservice Api",
                Email       = "*****@*****.**",
                JWTISSUER   = Configuration["AppConfig:JWTISSUER"],
                JWTKEY      = Configuration["AppConfig:JWTKEY"],
                Title       = "Api",
                Version     = "V1",
                xmlPath     = xmlPath
            });
            var DbConfiguration = Configuration.GetConnectionString("Dev");

            services.Configure <AppCustomConfig>(Configuration.GetSection("AppConfig"));
            DatabaseModule.Register(services, DbConfiguration);
            RepositoryModule.Register(services);
            ServiceModule.Register(services);
            services.AddControllers();
            services.AddApiVersioning(
                options =>
            {
                // reporting api versions will return the headers "api-supported-versions" and "api-deprecated-versions"
                options.ReportApiVersions = true;
            });
            services.AddVersionedApiExplorer(
                options =>
            {
                // add the versioned api explorer, which also adds IApiVersionDescriptionProvider service
                // note: the specified format code will format the version as "'v'major[.minor][-status]"
                options.GroupNameFormat = "'v'VVV";

                // note: this option is only necessary when versioning by url segment. the SubstitutionFormat
                // can also be used to control the format of the API version in route templates
                options.SubstituteApiVersionInUrl = true;
            });
        }
예제 #24
0
        public Factory()
        {
            var repositoryModule = new RepositoryModule();

            this.kernel = new StandardKernel(repositoryModule);
        }
예제 #25
0
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            var componentBootstrapper = new RepositoryModule();

            componentBootstrapper.Init(container);
        }
예제 #26
0
 public static void RegisterServices(this IServiceCollection service, IConfiguration configuration)
 {
     RepositoryModule.Configure(service, configuration);
     ServiceModule.Configure(service);
 }
예제 #27
0
 /// <summary>Registers the type mappings with the Unity container.</summary>
 /// <param name="container">The unity container to configure.</param>
 /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to
 /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks>
 public static void RegisterTypes(IUnityContainer container)
 {
     CoreModule.ConfigureModule(container);
     RepositoryModule.ConfigureModule(container);
     ServiceModule.ConfigureModule(container);
 }
예제 #28
0
        public void ConfigureServices(IServiceCollection services)
        {
            RepositoryModule.Load(services);
            ServiceModule.Load(services);
            ApplicationModule.Load(services);

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            var connection = Configuration["ConnectionStrings:MyConnStr"];
            //services.AddDbContext<j2pContext>(options => options.UseMySql(connection));

            //Config Token
            var signingConfigurations = new SigningConfigurations();

            services.AddSingleton(signingConfigurations);

            var tokenConfigurations = new TokenConfiguration
            {
                Audience = AUDIENCE,
                Issuer   = ISSUER,
                Seconds  = int.Parse(TimeSpan.FromDays(1).TotalSeconds.ToString())
            };

            services.AddSingleton(tokenConfigurations);
            services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();


            services.AddAuthentication(authOptions =>
            {
                authOptions.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                authOptions.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(bearerOptions =>
            {
                var paramsValidation = bearerOptions.TokenValidationParameters;
                paramsValidation.IssuerSigningKey = signingConfigurations.SigningCredentials.Key;
                paramsValidation.ValidAudience    = tokenConfigurations.Audience;
                paramsValidation.ValidIssuer      = tokenConfigurations.Issuer;

                // Valida a assinatura de um token recebido
                paramsValidation.ValidateIssuerSigningKey = true;

                // Verifica se um token recebido ainda é válido
                paramsValidation.ValidateLifetime = true;

                // Tempo de tolerância para a expiração de um token (utilizado
                // caso haja problemas de sincronismo de horário entre diferentes
                // computadores envolvidos no processo de comunicação)
                paramsValidation.ClockSkew = TimeSpan.Zero;
            });

            // Ativa o uso do token como forma de autorizar o acesso
            // a recursos deste projeto
            services.AddAuthorization(auth =>
            {
                auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder()
                               .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme‌​)
                               .RequireAuthenticatedUser().Build());
            });

            //Para todas as requisições serem necessaria o token, para um endpoint não exigir o token
            //deve colocar o [AllowAnonymous]
            //Caso remova essa linha, para todas as requisições que precisar de token, deve colocar
            //o atributo [Authorize("Bearer")]
            services.AddMvc(x =>
            {
                var policy = new AuthorizationPolicyBuilder()
                             .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme‌​)
                             .RequireAuthenticatedUser().Build();

                x.Filters.Add(new AuthorizeFilter(policy));
            });

            //services.AddMvc();

            services.AddCors();

            var config = new AutoMapper.MapperConfiguration(c =>
            {
                c.AddProfile(new ApplicationProfile());
            });

            var mapper = config.CreateMapper();

            services.AddSingleton(mapper);

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
        }
예제 #29
0
 public static void MapperModules(Container container)
 {
     ApplicationServiceModule.Register(container);
     RepositoryModule.Register(container);
     ServiceModule.Register(container);
 }