// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { Types = AssemblyTypesBuilder.GetAllExecutingContextTypes(); _hostingEnv.SetDefault(); var isDebug = _hostingEnv.IsDev(); var conStr = Configuration.GetConnectionString("SqlServer"); services.AddAppSettings(Configuration) .RegisterCommandQueryDbContext(conStr) .RegisterCommandsAndQueryServices(Types) .RegisterRepositories(Types); services.AddControllers(); }
public Fixture() { var path = Environment.CurrentDirectory; var services = new ServiceCollection(); var types = new List <Type>(); var assemblies = AppDomain.CurrentDomain .GetAssemblies(); // Todo Fix explicit adding of Qf.Persistence assembly //assemblies.Push(typeof(AccountsManager).Assembly); //assemblies.Push(typeof(AdminCommandService).Assembly); types.AddRange(AssemblyTypesBuilder.GetCommonExecutingContextTypes(assemblies)); var allTypes = types.ToArray(); var connectionString = Guid.NewGuid().ToString(); // Initialized in memory database services.RegisterCommandQueryDbContext(connectionString, true); // register repositories services.RegisterRepositories(allTypes); // register services services.RegisterCommandsAndQueryServices(allTypes); services.AddSingleton <ILoggerFactory, NullLoggerFactory>(); services.AddSingleton <IHostEnvironment, MockWebHostEnvironment>(); // IOC container services.AddScoped <IHttpContextAccessor, MockHttpContextAccessor>(); services.AddLogging(builder => builder.AddConsole()); ServiceProvider = services.BuildServiceProvider(); CommandContext = ServiceProvider.GetService <BaseCommandContext>(); var hostEnvironment = ServiceProvider.GetService <IHostEnvironment>(); hostEnvironment.SetDefault(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { Types = AssemblyTypesBuilder.GetAllExecutingContextTypes(); _hostingEnv.SetDefault(); var isDebug = _hostingEnv.IsDev(); var conStr = Configuration.GetConnectionString("SqlServer"); services.AddAppSettings(Configuration) .RegisterCommandQueryDbContext(conStr) .RegisterCommandsAndQueryServices(Types) .RegisterRepositories(Types); services.AddIdentity <Core.Model.User, Role>() .AddEntityFrameworkStores <BaseContext>() .AddDefaultTokenProviders(); services.Configure <IdentityOptions>(options => { // Password settings options.Password.RequireDigit = false; options.Password.RequiredLength = 4; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; options.Password.RequireLowercase = false; // User settings options.User.RequireUniqueEmail = true; }); #region Add CORS services.AddCors(options => options.AddPolicy("Cors", builder => { builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); #endregion #region Add Authentication var signingKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Tokens:Key"])); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(config => { config.RequireHttpsMetadata = false; config.SaveToken = true; config.TokenValidationParameters = new TokenValidationParameters() { IssuerSigningKey = signingKey, ValidateAudience = true, ValidAudience = this.Configuration["Tokens:Audience"], ValidateIssuer = true, ValidIssuer = this.Configuration["Tokens:Issuer"], ValidateLifetime = true, ValidateIssuerSigningKey = true }; }); #endregion // services.AddAuthentication(); services.AddControllers(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { Types = AssemblyTypesBuilder.GetAllExecutingContextTypes(); _hostingEnv.SetDefault(); var isDebug = _hostingEnv.IsDev(); var conStr = Configuration.GetConnectionString("SqlServer"); services.AddAppSettings(Configuration) .RegisterCommandQueryDbContext(conStr) .RegisterCommandsAndQueryServices(Types) .RegisterRepositories(Types) .RegisterGraphQL(Types) .AddHttpContextAccessor() .AddGraphQLServer(); services.AddIdentity <Core.Model.User, Role>() .AddEntityFrameworkStores <BaseCommandContext>() .AddDefaultTokenProviders(); services.Configure <IdentityOptions>(options => { // Password settings options.Password.RequireDigit = false; options.Password.RequiredLength = 4; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; options.Password.RequireLowercase = false; // User settings options.User.RequireUniqueEmail = true; }); #region Add CORS services.AddCors(options => options.AddPolicy("Cors", builder => { builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); #endregion #region Add Authentication var signingKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Tokens:Key"])); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddPolicyScheme("switch", "cookie or bearer", options => { options.ForwardDefaultSelector = context => { var bearerAuth = context.Request.Headers["Authorization"].FirstOrDefault()?.StartsWith("Bearer ") ?? false; // You could also check for the actual path here if that's your requirement: // eg: if (context.HttpContext.Request.Path.StartsWithSegments("/api", StringComparison.InvariantCulture)) return(JwtBearerDefaults.AuthenticationScheme); }; }) .AddJwtBearer(config => { config.RequireHttpsMetadata = false; config.SaveToken = true; config.TokenValidationParameters = new TokenValidationParameters() { IssuerSigningKey = signingKey, ValidateAudience = true, ValidAudience = this.Configuration["Tokens:Audience"], ValidateIssuer = true, ValidIssuer = this.Configuration["Tokens:Issuer"], ValidateLifetime = true, ValidateIssuerSigningKey = true }; }); #endregion services.AddControllers(); }
/// <summary> /// Compile all types and members /// </summary> public void Compile() { #if DEBUG //System.Diagnostics.Debugger.Launch(); #endif // Detect Free Apps Key var allAttributes = assemblies.SelectMany(x => x.CustomAttributes); var attr = allAttributes.FirstOrDefault(x => x.AttributeType.Name == AttributeConstants.FreeAppsKeyAttributeName && x.AttributeType.Namespace == AttributeConstants.Dot42AttributeNamespace); freeAppsKey = (attr != null) ? (string)attr.ConstructorArguments[0].Value : null; // Detect all types to include in the compilation var reachableContext = new ReachableContext(this, assemblies.Select(x => x.Name), rootClassNames); const bool includeAllJavaCode = false; using (Profile("for marking roots")) { assemblies.Concat(references.Where(IsLibraryProject)) .ToList() .AsParallel() .ForAll(assembly => reachableContext.MarkRoots(assembly, includeAllJavaCode)); reachableContext.MarkPatternIncludes(assemblies.Concat(references).ToList()); } using (Profile("for finding reachables")) reachableContext.Complete(); // Convert IL to java compatible constructs. using (Profile("for IL conversion")) ILConversion.ILToJava.Convert(reachableContext); // Convert all types var classBuilders = reachableContext.ClassBuilders.OrderBy(x => x.SortPriority) .ThenBy(x => x.FullName) .ToList(); using (Profile("for creating/implementing/fixup")) { classBuilders.ForEachWithExceptionMessage(x => x.Create(targetPackage)); classBuilders.ForEachWithExceptionMessage(x => x.Implement(targetPackage)); classBuilders.ForEachWithExceptionMessage(x => x.FixUp(targetPackage)); // update sort priority which might have changed after XType creation. classBuilders = classBuilders.OrderBy(x => x.SortPriority) .ThenBy(x => x.FullName) .ToList(); } if (StopCompilationBeforeGeneratingCode) { return; } List <Exception> errors = new List <Exception>(); using (Profile("for generating code")) { if (StopAtFirstError) { classBuilders.ForEachWithExceptionMessage(x => x.GenerateCode(targetPackage, StopAtFirstError)); } else { foreach (var classBuilder in classBuilders) { try { classBuilder.GenerateCode(targetPackage, StopAtFirstError); } catch (AggregateException ex) { errors.Add(new Exception("Error while compiling class " + classBuilder.FullName + ": " + string.Join("; ", ex.Flatten().InnerExceptions.Select(e => e.Message)), ex)); } catch (Exception ex) { errors.Add(new Exception("Error while compiling " + classBuilder.FullName + ": " + ex.Message, ex)); } } } } using (Profile("for creating annotations")) { classBuilders.ForEachWithExceptionMessage(x => x.CreateAnnotations(targetPackage)); if (AddAssemblyTypesAnnotations()) { AssemblyTypesBuilder.CreateAssemblyTypes(this, (Target.Dex.DexTargetPackage)targetPackage, reachableContext.ReachableTypes); } if (AddFrameworkPropertyAnnotations()) { DexImportClassBuilder.FinalizeFrameworkPropertyAnnotations(this, (Target.Dex.DexTargetPackage)targetPackage); } } // Compile all methods using (Profile("for compiling to target")) targetPackage.CompileToTarget(generateDebugInfo, mapFile); // Add structure annotations targetPackage.AfterCompileMethods(); // Verify targetPackage.VerifyBeforeSave(freeAppsKey); // Create MapFile, but don't optimize jet. optimizedMapFile = false; RecordScopeMapping(reachableContext); classBuilders.ForEachWithExceptionMessage(x => x.RecordMapping(mapFile)); if (errors.Count > 0) { throw new AggregateException(errors); } }