// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // get connection string
            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            // register data access and services dependencies
            DiModule.RegisterModule(services, connectionString);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            //Swagger

            services.AddSwaggerDocument(config =>
            {
                config.PostProcess = document =>
                {
                    document.Info.Version     = "V1";
                    document.Info.Title       = "SEDC TODO app";
                    document.Info.Description = "This is our first ToDo api app";
                    document.Info.Contact     = new NSwag.OpenApiContact
                    {
                        Name  = "Dimitar Risteski",
                        Email = "*****@*****.**"
                    };
                };
            });
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            DiModule.RegisterModule(services, connectionString);
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Пример #3
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);

            var appConfig = Configuration.GetSection("AppSettings");

            services.Configure <AppSettings>(appConfig);

            var appSettings = appConfig.Get <AppSettings>();
            var secret      = Encoding.ASCII.GetBytes(appSettings.Secret);

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = true;
                x.TokenValidationParameters =
                    new Microsoft.IdentityModel.Tokens.TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(secret),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });

            // If someone like Controllers ask for a instance of IUserService, provide them with the class UserService();
            services.AddTransient <IUserService, UserService>();
            services.AddTransient <INoteService, NoteService>();
            DiModule.RegisterModule(services, appSettings.NoteAppConnectionString);
        }
        public void ConfigureServices(IServiceCollection services)
        {
            // get the connection string
            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            // register DB CONTEXT (DataAccess dependencies)
            DiModule.Register(services, connectionString);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            //SWAGER:
            services.AddSwaggerDocument(config =>
            {
                config.PostProcess = document =>
                {
                    document.Info.Version     = "V1";
                    document.Info.Title       = "Homework-WebAPI: ToDo App";
                    document.Info.Description = "My First WebAPI App";
                    document.Info.Contact     = new NSwag.OpenApiContact
                    {
                        Name  = "Dushko Videski",
                        Email = "*****@*****.**"
                    };
                };
            });
        }
Пример #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection 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;
            });

            services.AddAutoMapper(options => options.AddProfile <MapperProfile>());

            DiModule.RegisterModule(services, Configuration.GetConnectionString("LamazonDbConnection"));

            services.ConfigureApplicationCookie(options =>
            {
                options.Cookie.HttpOnly   = true;
                options.ExpireTimeSpan    = TimeSpan.FromMinutes(60);
                options.LoginPath         = "/Accounts/LogIn";
                options.AccessDeniedPath  = "/Accounts/LogIn";
                options.SlidingExpiration = true;
            });

            services.AddTransient <IUserService, UserService>();
            services.AddTransient <IProductService, ProductService>();
            services.AddTransient <IOrderService, OrderService>();
            services.AddTransient <IInvoiceService, InvoiceService>();

            services.AddMvc(options => options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute()))
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <RegisterViewModelValidation>())
            .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <LoginViewModelValidation>());
        }
Пример #6
0
        public void TestInitialize()
        {
            _dataRootPath            = Path.Combine(Directory.GetCurrentDirectory(), "Data", "EndToEndTest");
            _testDirPath             = Path.Combine(Directory.GetCurrentDirectory(), "EndToEndTest");
            _deploymentDirPath       = Path.Combine(_testDirPath, "Deployments");
            _applicationsInstallPath = Path.Combine(_testDirPath, Constants.ApplicationsRootFolderName);

            FileUtils.CopyDir(_dataRootPath, _deploymentDirPath, overwrite: true).Wait();

            CopyTestProcessExeToTestApps();

            _diContainer = new UnityContainer();
            DiModule.RegisterTypes(_diContainer, new YamsConfigBuilder("UseDevelopmentStorage=true", "deploymentId1", "1", "instanceId", _applicationsInstallPath).Build());

            // Replace the IRemoteDirectory default implementation (which uses Azure) with a LocalDirectory implementation
            // so we can use local test data.
            _diContainer.RegisterType <IRemoteDirectory>(new ContainerControlledLifetimeManager(),
                                                         new InjectionFactory(
                                                             c => new LocalDirectory(_deploymentDirPath)));

            IUpdateSessionManager updateSessionManager = new StubIUpdateSessionManager
            {
                TryStartUpdateSessionString = applicationId => Task.FromResult(true),
                EndUpdateSessionString      = applicationId => Task.FromResult(true)
            };

            // Replace the update session manager with a stub that always starts an update session (since we don't have multiple instances
            // updating in a test)
            _diContainer.RegisterInstance(updateSessionManager);

            // we don't start yams because that will make it update based on a timer that is hard to manage in a test. Instead, we call
            // applicationUpdateManager.CheckForUpdates() manually in a test.
            _yamsEntryPoint = new YamsEntryPoint(_diContainer);
        }
Пример #7
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);
            var appConfig = Configuration.GetSection("AppSettings");

            services.Configure <AppSettings>(appConfig);
            var appSettings = appConfig.Get <AppSettings>();
            var secret      = Encoding.ASCII.GetBytes(appSettings.Secret);

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = true;
                x.TokenValidationParameters =
                    new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(secret),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });
            services.AddTransient <IUserService, UserService>();

            services.AddTransient <ITicketService, TicketService>();
            services.AddTransient <ISessionService, SessionService>();
            DiModule.RegisterModuule(services, appSettings.LotoAppConnectionString);
        }
Пример #8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection 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;
            });



            // I will use manuel mapper so this is for deleting
            //var mappingCongig = new MapperConfiguration(mc =>
            //{
            //    mc.AddProfile(new MapperProfile());
            //});



            var conf             = Configuration.GetSection("AppSettings");
            var connectionString = conf["TodoConnectionString"];

            DiModule.RegisterModule(services, connectionString);

            services.AddMvc(options => {
                var policy = new AuthorizationPolicyBuilder()
                             .RequireAuthenticatedUser()
                             .Build();
                options.Filters.Add(new AuthorizeFilter(policy));
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
Пример #9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection 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;
            });
            services.AddAutoMapper(opts =>
            {
                opts.AddProfile <MapperProfile>();
            });
            DiModule.RegisterModules(services, Configuration.GetConnectionString("HomeCinemaDbConnection"));
            services.ConfigureApplicationCookie(options =>
            {
                options.Cookie.HttpOnly   = true;
                options.ExpireTimeSpan    = TimeSpan.FromMinutes(60);
                options.LoginPath         = "/Users/LogIn";
                options.AccessDeniedPath  = "/Users/LogIn";
                options.SlidingExpiration = true;
            });

            services.AddTransient <IUserService, UserService>();
            services.AddTransient <IMovieService, MovieService>();
            services.AddTransient <IUserActionService, UserActionService>();
            services.AddTransient <IRecommenderService, UserBasedRecommender>();
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Пример #10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection 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;
            });



            services.AddTransient <IUserService, UserService>();
            services.AddTransient <IForumService, ForumService>();
            services.AddTransient <IPostService, PostService>();
            services.AddTransient <IPostReplyService, PostReplyService>();



            DiModule.RegisterModules(
                services,
                Configuration.GetConnectionString("ForumDbConnection")
                );


            services.AddAutoMapper(opts =>
            {
                opts.AddProfile <MapProfile>();
            });
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Пример #11
0
 static void Main(string[] args)
 {
     string path = @"..\..\DebuggingConsoleApp.csproj";
     SimpleStubsGenerator stubsGenerator =
         new DiModule(path, @"..\..\Properties\SimpleStubs.generated.cs").StubsGenerator;
     string stubs = stubsGenerator.GenerateStubs(path).Result;
     File.WriteAllText(@"..\..\Properties\SimpleStubs.generated.cs", stubs);
 }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // get connection string
            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            // register data access dependencies
            DiModule.RegisterModule(services, connectionString);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Пример #13
0
        public async Task TestGenerateStubs()
        {
            string path = //@"C:\projects\JasperMain\Product\Jasper.Test\Jasper.Test.csproj";
                          @"..\..\TestClassLibraryTest.csproj";
            //"..\\..\\SimpleStubsTest.csproj";
            SimpleStubsGenerator stubsGenerator =
                new DiModule(path, @"..\..\Properties\SimpleStubs.generated.cs").StubsGenerator;
            string stubs = await stubsGenerator.GenerateStubs(path);

            File.WriteAllText(@"..\..\Properties\SimpleStubs.generated.cs", stubs);
        }
Пример #14
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient <IOrderService, OrderService>();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            //services.AddSwaggerGen(c =>
            //{
            //    c.SwaggerDoc("v1", new Info { Title = "Order API", Version = "v1" });
            //});

            DiModule.RegisterModule(services, Configuration.GetConnectionString("OrderConnectionString"));
        }
Пример #15
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddJsonOptions(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);;

            services.AddTransient <IUserService, UserService>();
            services.AddTransient <IQuizService, QuizService>();
            services.AddTransient <IQuestionService, QuestionService>();
            services.AddTransient <IAnswerService, AnswerService>();


            services.AddAutoMapper(opts =>
            {
                opts.AddProfile <MapProfile>();
            });



            var appConfig = Configuration.GetSection("AppSettings");

            services.Configure <AppSettings>(appConfig);

            var appSettings = appConfig.Get <AppSettings>();
            var secret      = Encoding.ASCII.GetBytes(appSettings.Secret);

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = true;
                x.TokenValidationParameters =
                    new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(secret),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });
            DiModule.RegisterModules(
                services,
                appSettings.Quiz_coDbConnection
                );
        }
Пример #16
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(opt =>
            {
                opt.AddPolicy("CorsPolicy", builder =>
                              builder.AllowAnyOrigin()
                              .AllowAnyMethod()
                              .AllowAnyHeader()
                              .AllowCredentials());
            });


            // get connection string
            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            // register data access dependencies
            DiModule.RegisterModule(services, connectionString);

            // service registration
            services.AddTransient <IUserService, UserService>();
            services.AddTransient <INoteService, NoteService>();

            var jwtSection = Configuration.GetSection("JwtSettings");

            services.Configure <JwtSettings>(jwtSection);
            var jwtSettings = jwtSection.Get <JwtSettings>();

            var secret = Encoding.ASCII.GetBytes(jwtSettings.Secret);

            services.AddAuthentication(
                x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = true;
                x.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(secret),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Пример #17
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //Connection string
            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            //Data access dependencies
            DiModule.RegisterModule(services, connectionString);

            //Services
            services.AddTransient <IUserService, UserService>();
            services.AddTransient <IToDoTaskService, ToDoTaskService>();
            services.AddTransient <IToDoSubTaskService, ToDoSubTaskService>();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Пример #18
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //CORS
            services.AddCors(options => {
                options.AddPolicy("CorsPolicy", builder =>
                                  builder.AllowAnyOrigin()
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials());
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            // Configuring AppSettings section
            var appConfig = Configuration.GetSection("AppSettings");

            services.Configure <AppSettings>(appConfig);

            // Using AppSettings
            var appSettings = appConfig.Get <AppSettings>();
            var secret      = Encoding.ASCII.GetBytes(appSettings.Secret);

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }
                                       ).AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = true;
                x.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(secret),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            }
                                                      );
            // IUserServce => new UserService();
            services.AddTransient <IUserService, UserService>();
            // INoteService => new NoteService();
            services.AddTransient <INoteService, NoteService>();
            DiModule.RegisterModule(services, appSettings.NoteAppConnectionString);
        }
Пример #19
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            DiModule.RegisterModule(services, connectionString);

            services.AddTransient <IStudentService, StudentService>();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "My Api", Version = "v1"
                });
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Пример #20
0
        public override bool Execute()
        {
            try
            {
                LogMessage("Generating stubs");
                DiModule diModule = new DiModule(ProjectPath, OutputPath);
                Directory.CreateDirectory(Path.GetDirectoryName(OutputPath));
                File.WriteAllText(OutputPath, diModule.StubsGenerator.GenerateStubs(ProjectPath).Result);
                return(true);
            }
            catch (Exception e)
            {
                LogMessage(e.ToString());
            }

            return(false);
        }
Пример #21
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //Get connection string and register repositories
            var config = Configuration.GetSection("ConnectionString");

            DiModule.RegisterModule(services, config["BicycleDbConnection"]);

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddScoped <ValidateModelFIlter>();


            var jwtSettingSection = Configuration.GetSection(nameof(JwtSettings));

            services.Configure <JwtSettings>(jwtSettingSection);
            var jwtSettings = jwtSettingSection.Get <JwtSettings>();
            var key         = Encoding.ASCII.GetBytes(jwtSettings.Key);

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(options =>
            {
                options.RequireHttpsMetadata      = false;
                options.SaveToken                 = true;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateAudience         = false,
                    ValidateIssuer           = false
                };
            });

            services.AddAutoMapper(typeof(MappingProfile));

            //register swagger
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "BBG Api", Version = "v1"
                });
            });
        }
Пример #22
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection 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;
            });

            DiModule.RegisterRepositories(services);

            // Di services registration
            services.AddTransient <IUserService, UserService>();
            services.AddTransient <IPizzaOrderService, PizzaOrderService>();

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
Пример #23
0
        public void ConfigureServices(IServiceCollection services)
        {
            // CORS
            services.AddCors(opt =>
            {
                opt.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin()
                              .AllowAnyMethod()
                              .AllowAnyHeader()
                              .AllowCredentials());
            });

            // get the connection string
            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            // DB CONTEXT and REPOSITORIES registration
            DiModule.Register(services, connectionString);


            // SERVICES registration
            services.AddTransient <IStudentService, StudentService>();


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            //SWAGER:
            services.AddSwaggerDocument(config =>
            {
                config.PostProcess = document =>
                {
                    document.Info.Version     = "V1";
                    document.Info.Title       = "Polar Cape test assignment";
                    document.Info.Description = "Simplified Collage System App";
                    document.Info.Contact     = new NSwag.OpenApiContact
                    {
                        Name  = "Dushko Videski",
                        Email = "*****@*****.**"
                    };
                };
            });
        }
Пример #24
0
        static void Main(string[] args)
        {
            CommandLineParser parser = new CommandLineParser();

            parser.Parse(args);

            string projectPath = parser.Arguments["-ProjectPath"];

            if (string.IsNullOrEmpty(projectPath) || !File.Exists(projectPath))
            {
                Console.WriteLine(DecorateMessage($"ProjectPath cannot be empty"));
                return;
            }
            if (!File.Exists(projectPath))
            {
                Console.WriteLine(DecorateMessage($"{projectPath} does not exist"));
                return;
            }

            string outputPath = parser.Arguments["-OutputPath"];

            if (string.IsNullOrEmpty(outputPath))
            {
                Console.WriteLine(DecorateMessage($"OutputPath cannot be empty"));
                return;
            }

            string configuration = parser.Arguments["-Configuration"];

            if (string.IsNullOrEmpty(configuration))
            {
                Console.WriteLine(DecorateMessage($"Configuration cannot be empty"));
                return;
            }

            string platform = parser.Arguments["-Platform"];

            if (string.IsNullOrEmpty(platform))
            {
                Console.WriteLine(DecorateMessage($"Platform cannot be empty"));
                return;
            }

            DiModule diModule = new DiModule(projectPath, outputPath);

            Directory.CreateDirectory(Path.GetDirectoryName(outputPath));

            Console.WriteLine(DecorateMessage($"Generating stubs for project: {projectPath}"));

            try
            {
                string stubsCode = diModule.StubsGenerator.GenerateStubs(projectPath, configuration, platform).Result;
                Console.WriteLine(DecorateMessage($"Writing stubs to file: {outputPath}"));
                File.WriteAllText(outputPath, stubsCode);
            }
            catch (ReflectionTypeLoadException ex)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Exception exSub in ex.LoaderExceptions)
                {
                    sb.AppendLine(exSub.Message);
                    FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
                    if (exFileNotFound != null)
                    {
                        if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                        {
                            sb.AppendLine("Fusion Log:");
                            sb.AppendLine(exFileNotFound.FusionLog);
                        }
                    }
                    sb.AppendLine();
                }
                string errorMessage = sb.ToString();
                Console.WriteLine(DecorateMessage($"Failed to generate stubs: {errorMessage}"));
            }
            catch (Exception e)
            {
                Console.WriteLine(DecorateMessage($"Failed to generate stubs: {e.ToString()}"));
            }
        }
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(opt =>
            {
                opt.AddPolicy("CorsPolicy", builder =>
                              builder.AllowAnyOrigin()
                              .AllowAnyMethod()
                              .AllowAnyHeader()
                              .AllowCredentials());
            });


            // get connection string
            var connectionString = Configuration.GetConnectionString("DefaultConnection");

            // register data access dependencies
            DiModule.RegisterModule(services, connectionString);

            // service registration
            services.AddTransient <IUserService, UserService>();
            services.AddTransient <INoteService, NoteService>();

            var jwtSection = Configuration.GetSection("JwtSettings");

            services.Configure <JwtSettings>(jwtSection);
            var jwtSettings = jwtSection.Get <JwtSettings>();

            var secret = Encoding.ASCII.GetBytes(jwtSettings.Secret);

            services.AddAuthentication(
                x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = true;
                x.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(secret),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            //SWAGER:
            services.AddSwaggerDocument(config =>
            {
                config.PostProcess = document =>
                {
                    document.Info.Version     = "V1";
                    document.Info.Title       = "Booking Airplane Tickets App";
                    document.Info.Description = "Nebb-Four Solutions Interview Coding Assignment";
                    document.Info.Contact     = new NSwag.OpenApiContact
                    {
                        Name  = "Dushko Videski",
                        Email = "*****@*****.**"
                    };
                };
            });
        }
Пример #26
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();
            services.AddControllers();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Wedding Organizer API", Version = "v1"
                });
                c.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme()
                {
                    Description = "Standard Authorization header using the Bearer scheme. Example: \"Bearer {token}\"",
                    In          = ParameterLocation.Header,
                    Name        = "Authorization",
                    Type        = SecuritySchemeType.ApiKey
                });
                c.AddSecurityRequirement(new OpenApiSecurityRequirement()
                {
                    { new OpenApiSecurityScheme
                      {
                          Reference = new OpenApiReference
                          {
                              Type = ReferenceType.SecurityScheme,
                              Id   = "oauth2"
                          },
                          Scheme = "oauth2",
                          Name   = "Bearer"
                      },
                      new string [] {} }
                });
            });

            var jwtSettingsSection = Configuration.GetSection("JwtSettings");

            services.Configure <JwtSettings>(jwtSettingsSection);

            // configure jwt authentication
            var jwtSettings = jwtSettingsSection.Get <JwtSettings>();
            var key         = Encoding.ASCII.GetBytes(jwtSettings.Secret);

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = true;
                x.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });
            services.AddTransient <IUserService, UserService>();
            services.AddTransient <IBudgetItemService, BudgetItemService>();
            services.AddTransient <IGuestService, GuestService>();
            services.AddTransient <IRestaurantService, RestaurantService>();
            DiModule.RegisterModule(services, Configuration.GetConnectionString("WeddingOrganizer"));
        }
Пример #27
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            DiModule.RegisterModules(services, Configuration.GetConnectionString("ForumDatabase"));

            services.AddControllersWithViews();
        }