public virtual void OnInitialize() { //Registrazione della sessione di default SessionFactory.RegisterDefaultDataSession <MockDataSession <TScenario, TransientScenarioOption <TScenario> > >(); //Registrazione dei servizi ServiceResolver.Register <IIdentityClient, MockIdentityClient>(); ServiceResolver.Register <ICaptchaValidatorService, MockCaptchaValidatorService>(); ServiceResolver.Register <ISemperPrecisMemoryCache, SemperPrecisMemoryCache>(); //Creazione del controller dichiarato Controller = new TApiController(); Scenario = Controller.DataSession.GetScenario <TScenario>(); //Recupero l'utente da usare nel testa var defaultShooterIdentity = GetIdentityUser(); if (defaultShooterIdentity == null) { throw new InvalidProgramException("Shooter for identity is invalid"); } //Inizializzazione del controller context e impostazione dell'identity UpdateIdentityUser(defaultShooterIdentity); }
public void ConstructorSetsCorrectCommandTypes() { ServiceResolver.Register <IApiRequest>(() => null); var vm = new HomePageViewModel(); Assert.IsInstanceOfType(vm.StartRound, typeof(StartRoundCommand)); Assert.IsInstanceOfType(vm.Sync, typeof(AsyncCommand)); }
public void Sets_Default_Values() { ServiceResolver.Register <ISettings>(() => new TestSettings( Constants.APIHostConfigKey, "http://api.com")); var vm = new ConfigurationViewModel(); Assert.AreEqual(1, vm.Crumbs.Count); Assert.AreEqual(vm.Crumbs.ElementAt(0).Title, "Settings"); Assert.IsNotNull(vm.Save); Assert.AreEqual("http://api.com", vm.ApiHost); }
/// <summary> /// Initializes a new instance of the <see cref="App"/> class. /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { // register services with PCL ServiceResolver.Register <ISettings>(() => new Settings()); ServiceResolver.Register <IBreadcrumbNavigationEvent>(() => new BreadcrumbNavigationHandler()); ServiceResolver.Register <IApiRequest>(() => new ApiRequest()); ServiceResolver.Register <IFileHandler>(() => new FileHandler()); // set the navigator for our classses. BaseViewModel.Navigator = new NavigationService(); this.InitializeComponent(); this.Suspending += this.OnSuspending; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseHttpsRedirection(); app.UseSwagger(); app.UseSwaggerUI(options => options.ConfigureSwaggerUI()); app.UseMvc(); app.UseCors("AllowAll"); ServiceResolver.Register(app.ApplicationServices); TodoDbInitializer.Seed(app.ApplicationServices.GetRequiredService <TodoDbContext>()).ConfigureAwait(false); }
static void Main(string[] args) { //Configurazione del tracer Tracer.Append(typeof(Log4NetTracer)); Tracer.Info($"[Settings] Working on environment '{ConfigurationFactory<SemperPrecisStageTrackerConfiguration>.Instance.EnvironmentName}' (from configuration factory)"); //Select provider for data storage SettingsUtils.Switch(ConfigurationFactory <SemperPrecisStageTrackerConfiguration> .Instance.Storage.Provider, new Dictionary <string, Action> { { "Mockup", SessionFactory.RegisterDefaultDataSession <MockDataSession <SimpleScenario> > }, { "Sql", SessionFactory.RegisterDefaultDataSession <EntityFrameworkDataSession <SemperPrecisStageTrackerContext> > } }); // identity client SettingsUtils.Switch(ConfigurationFactory <SemperPrecisStageTrackerConfiguration> .Instance.Storage.Provider, new Dictionary <string, Action> { { "Mockup", ServiceResolver.Register <IIdentityClient, MockIdentityClient> }, { "Sql", ServiceResolver.Register <IIdentityClient, SqlIdentityClient> } }); ServiceResolver.Register <ISemperPrecisMemoryCache, SemperPrecisMemoryCache>(); ServiceResolver.Register <ICaptchaValidatorService, CaptchaValidatorService>(); //Definizione del nome e versione del sistema var assembly = Assembly.GetEntryAssembly()?.GetName() ?? throw new NullReferenceException("Assembly not found"); ApplicationName = assembly.Name; ApplicationVersion = $"v{assembly.Version?.Major ?? 0}" + $".{assembly.Version?.Minor ?? 0}" + $".{assembly.Version?.Build ?? 0}"; var builder = WebApplication.CreateBuilder(args); builder.Host.ConfigureAppConfiguration((hostContext, config) => { var isDev = hostContext.HostingEnvironment.IsDevelopment(); if (isDev) { config.AddUserSecrets <Program>(); } var settings = config.Build(); if (!isDev) { // use az key vault var kvName = settings["azKVName"]; if (string.IsNullOrEmpty(kvName)) { throw new NullReferenceException("Azure KeyVault name not provided"); } var vaultName = $"https://{kvName}.vault.azure.net/"; var azureServiceTokenProvider = new AzureServiceTokenProvider(); var keyVaultClient = new KeyVaultClient( new KeyVaultClient.AuthenticationCallback( azureServiceTokenProvider.KeyVaultTokenCallback)); config.AddAzureKeyVault(vaultName, keyVaultClient, new DefaultKeyVaultSecretManager()); } }); // register configuration across application ServiceResolver.Register <IConfiguration>(builder.Configuration); builder.Services.AddCors(options => { var blazorEndpoints = builder.Configuration.GetSection("blazorEndpoints").Get <string[]>(); if (blazorEndpoints != null && blazorEndpoints.Length > 0) { options.AddPolicy(name: corsPolicy, builder => builder .WithOrigins(blazorEndpoints) .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); } else { options.AddPolicy(name: corsPolicy, (builder) => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); } }); //Aggiungo l'autentications basic e il default di schema builder.Services .AddAuthentication(o => o.DefaultScheme = BasicAuthenticationOptions.Scheme) .AddBasicAuthentication(); builder.Services.AddControllers().AddJsonOptions(options => { options.JsonSerializerOptions.WriteIndented = false; options.JsonSerializerOptions.DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull; }); builder.Services.AddHealthChecks(); builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "SemperPrecisStageTracker", Version = "v1" }); c.OperationFilter <PermissionsFilter>(); c.AddSecurityDefinition("basicAuth", new OpenApiSecurityScheme() { Type = SecuritySchemeType.Http, Scheme = "basic", Description = "Input your username and password to access this API", In = ParameterLocation.Header, }); c.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "basicAuth" } }, new List <string>() } }); }); var app = builder.Build(); var enableDev = bool.Parse(builder.Configuration["enableDev"] ?? "false"); if (app.Environment.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "SemperPrecisStageTracker v1")); } else { if (enableDev) { app.UseDeveloperExceptionPage(); } } app.UseHttpsRedirection(); app.UseRouting(); //Abilito CORS app.UseCors(corsPolicy); //Utilizzo l'autenticazione app.UseAuthentication(); app.UseAuthorization(); if (app.Environment.IsDevelopment() || enableDev) { app.UseExceptionHandler(c => c.Run(async context => { var exception = context.Features .Get <IExceptionHandlerPathFeature>() .Error; var response = new Dictionary <string, IList <string> > { { "", new List <string> { exception.Message } } }; await context.Response.WriteAsJsonAsync(response); })); } app.UseEndpoints(endpoints => { endpoints.MapHealthChecks("/healthz"); endpoints.MapGet("/", async context => { await context.Response.WriteAsync("Hi!"); }); endpoints.MapControllers(); }); app.Run(); }
public void Start() { //register dummy api request type. ServiceResolver.Register <IApiRequest>(() => null); ServiceResolver.Register <ISettings>(() => new TestSettings(true)); }
public void Start() { ServiceResolver.Register <IApiRequest>(() => null); }
public void Start() { //register dummy api request type. ServiceResolver.Register <IApiRequest>(() => new TestAPI()); }
public IBootstrapperLifestyle UseDI <T>(T container) where T : IContainer { _instance = new Bootstrapper(container); ServiceResolver.Register(_instance._container); return(_instance); }
public IBootstrapperLifestyle UseDI <T>() where T : IContainer { _instance = new Bootstrapper(Activator.CreateInstance <T>()); ServiceResolver.Register(_instance._container); return(_instance); }