Last active
July 15, 2020 15:04
-
-
Save MufidJamaluddin/8160ace3970e34d29d2a8bdeb92ed6fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace IssueTracker | |
{ | |
public class Startup | |
{ | |
public virtual void ConfigureDatabase(IServiceCollection services) | |
{ | |
if (!int.TryParse(Configuration["DatabasePool"], out int dbPoolSize)) | |
{ | |
dbPoolSize = DEFAULT_MAX_POOL_SIZE; | |
} | |
services.AddDbContextPool<IssueTrackerDbContext>((options) => | |
{ | |
options.UseSqlServer(Configuration.GetConnectionString("IssueTrackerDB")); | |
}, dbPoolSize); | |
services.AddDbContextPool<PaymentDbContext>((options) => | |
{ | |
options.UseSqlServer(Configuration.GetConnectionString("PaymentDB")); | |
}, dbPoolSize); | |
} | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
... | |
ConfigureDatabase(services); | |
services.AddIssueTrackerDependency(); | |
... | |
} | |
} | |
... | |
public static class IssueTrackerDependencyManager | |
{ | |
public static void AddIssueTrackerDependency(this IServiceCollection services) | |
{ | |
/** | |
* ADD DI TRACKER (SINGLETON, instansiasi sekali selama aplikasi jalan) | |
**/ | |
services.AddSingleton<ILogTracker, LogTracker>(); | |
/** | |
* ADD DI REPOSITORY DAN SERVICE (SCOPED, instansiasi sekali per request yang membutuhkan) | |
**/ | |
services.AddScoped<ITransactionRepository, TransactionRepository>(); | |
services.AddScoped<IUserRepository, UserRepository>(); | |
services.AddScoped<ICategoryRepository, CategoryRepository>(); | |
services.AddScoped<ITicketStatusRepository, TicketStatusRepository>(); | |
services.AddScoped<ITicketRepository, TicketRepository>(); | |
services.AddScoped<IAuthServices, AuthServices>(); | |
services.AddScoped<IUserServices, UserServices>(); | |
services.AddScoped<ICategoryServices, CategoryServices>(); | |
services.AddScoped<ITicketServices, TicketServices>(); | |
services.AddScoped<ITicketStatusServices, TicketStatusServices>(); | |
/** | |
* ADD DI REPOSITORY DAN SERVICE (TRANSIENT, setiap butuh maka lakukan instansiasi baru) | |
**/ | |
services.AddTransient<IJWTGenerator, JWTGenerator>(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment