public static ContainerBuilder Build(ContainerBuilder builder, bool sentryEnabled = false) { // Register external dependencies FoundationWebAutofac.Build(builder); AcumaticaHttpAutofac.Build(builder); ShopifyApiAutofac.Build(builder); // Logging registrations builder.RegisterType <DefaultFormatter>().As <ILogFormatter>().InstancePerLifetimeScope(); builder.Register(x => new NLogger(LoggerName, sentryEnabled: sentryEnabled, formatter: x.Resolve <ILogFormatter>())) .As <IPushLogger>() .InstancePerLifetimeScope(); // TODO *** decide if it's necessary to implement this for Batch stuff!! // //.InstancePerBackgroundJobIfTrue(containerForHangFire); // System-level Persistence always uses the MonsterConfig for its Connection String // var connectionString = MonsterConfig.Settings.SystemDatabaseConnection; // Persistence - System-level // SqlConnection/DbConnection are used by // builder .Register(ctx => { var connection = new SqlConnection(connectionString); connection.Open(); return(connection); }) .As <SqlConnection>() .As <DbConnection>() .InstancePerLifetimeScope(); builder.RegisterType <MasterRepository>().InstancePerLifetimeScope(); // Persistence - Instance-level Contexts // builder.RegisterType <InstanceContext>().InstancePerLifetimeScope(); builder.RegisterType <MiscPersistContext>().InstancePerLifetimeScope(); builder.RegisterType <ProcessPersistContext>().InstancePerLifetimeScope(); // Process Registrations // RegisterIdentityPlumbing(builder); RegisterMiscellaneous(builder); RegisterShopifyProcess(builder); RegisterAcumaticaProcess(builder); RegisterSyncProcess(builder); RegisterPayoutProcess(builder); // Crypto faculties // builder.Register <ICryptoService>( x => new AesCrypto(MonsterConfig.Settings.EncryptKey, MonsterConfig.Settings.EncryptIv)); return(builder); }
IContainer Build( string connStringOverride = null, string loggerName = "Monster.System") { var builder = new ContainerBuilder(); // Register external assemblies FoundationWebAutofac.Build(builder); // Register Acumatica library and inject settings AcumaticaHttpAutofac.Build(builder); builder.Register <AcumaticaHttpSettings>( x => AcumaticaHttpSettings.FromConfig()); // Acumatica Bank Import API screen builder.RegisterType <Screen>().InstancePerLifetimeScope(); // Register Shopify library and inject settings ShopifyApiAutofac.Build(builder); builder.Register <ShopifyHttpSettings>( x => ShopifyHttpSettings.FromConfig()); // Cryptographic builder.Register <ICryptoService>( x => { var settings = MonsterConfig.Settings; return(new AesCrypto(settings.EncryptKey, settings.EncryptIv)); }); // Logging registrations builder.RegisterType <DefaultFormatter>() .As <ILogFormatter>() .InstancePerLifetimeScope(); builder.Register(x => new NLogger(loggerName, x.Resolve <ILogFormatter>())) .As <IPushLogger>() .InstancePerLifetimeScope(); // Database connectivity builder.RegisterType <PersistContext>() .InstancePerLifetimeScope(); // TODO *** Need to implement this!! //.InstancePerBackgroundJobIfTrue(containerForHangFire); // Persistence Repositories builder.RegisterType <PayoutPersistRepository>().InstancePerLifetimeScope(); builder.RegisterType <InventoryPersistRepository>().InstancePerLifetimeScope(); builder.RegisterType <TenantContextRepository>().InstancePerLifetimeScope(); // Processes and Workers builder.RegisterType <ShopifyPayoutPullWorker>().InstancePerLifetimeScope(); builder.RegisterType <AcumaticaPayoutPushWorkerScreen>().InstancePerLifetimeScope(); builder.RegisterType <PayoutProcess>().InstancePerLifetimeScope(); return(builder.Build()); }