public void ConfigureServices(IServiceCollection services) { services.AddSingleton <RemoteDatabase>((serviceProvider) => { var http = serviceProvider.GetRequiredService <HttpClient>(); http.BaseAddress = new Uri(ServerUrl); var database = new RemoteDatabase(http); return(database); }); services.AddSingleton <IDatabase>(provider => provider.GetRequiredService <RemoteDatabase>()); services.AddSingleton <Workspace>((serviceProvider) => { var objectFactory = new Allors.Workspace.ObjectFactory(MetaPopulation.Instance, typeof(User)); var workspace = new Workspace(objectFactory); return(workspace); }); var implementationInstance = new AllorsAuthenticationStateProviderConfig { AuthenticationUrl = "/TestAuthentication/Token", }; services.AddSingleton(implementationInstance); services.AddScoped <AllorsAuthenticationStateProvider>(); services.AddScoped <AuthenticationStateProvider>(provider => provider.GetRequiredService <AllorsAuthenticationStateProvider>()); services.AddAuthorizationCore(); services.AddBootstrapCSS(); }
private void ThisAddIn_Startup(object sender, System.EventArgs e) => AsyncContext.Run(async() => { var configuration = new Configuration(); var httpClientHandler = new HttpClientHandler { UseDefaultCredentials = true }; var httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(configuration.AllorsDatabaseAddress), }; var serviceProvider = new ServiceCollection() // TODO: use DI logging //.AddLogging() .AddSingleton <IMessageService, MessageService>() .AddSingleton <IErrorService, ErrorService>() .BuildServiceProvider(); this.database = new RemoteDatabase(httpClient); var objectFactory = new ObjectFactory(MetaPopulation.Instance, typeof(User)); var workspace = new Workspace(objectFactory); this.Client = new Client(this.database, workspace); var program = new Program(serviceProvider, this.Client); var office = new Office(); this.AddIn = new AddIn(this.Application, program, office); this.Ribbon.AddIn = this.AddIn; this.Ribbon.Authentication = new Authentication(this.Ribbon, database, this.Client, configuration); await program.OnStart(this.AddIn); });