/
AuthenticatorStartup.cs
51 lines (46 loc) · 1.78 KB
/
AuthenticatorStartup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using Authenticator.Domain.Aggregates.User;
using Authenticator.Domain.Aggregates.User.Services;
using Authenticator.Infrastructure.MongoRepository;
using Authenticator.Infrastructure.InMemoryRepository;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Authenticator.API
{
public class AuthenticatorStartup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddHealthChecks();
var databaseUrl = Environment.GetEnvironmentVariable("DATABASE_URL");
if (databaseUrl != null)
{
services.AddSingleton<IDatabaseProvider>(new MongoDatabaseProvider(databaseUrl));
services.AddSingleton<IAccountRepository, MongoAccountRepository>();
}
else
{
Console.WriteLine("DATABASE_URL is not set. In memory account repository will be used.");
services.AddSingleton<IAccountRepository, InMemoryAccountRepository>();
}
services.AddTransient<ILoginService, LoginService>();
services.AddTransient<IRegistrationService, RegistrationService>();
services.AddControllers();
}
public void Configure(
IApplicationBuilder applicationBuilder,
IWebHostEnvironment environment,
ILogger<AuthenticatorStartup> logger)
{
applicationBuilder.UseHttpsRedirection();
applicationBuilder.UseRouting();
applicationBuilder.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHealthChecks("/healthz");
});
}
}
}