Dependency and unit-of-work registration¶
AutofacExtensions.RegisterCommonDependencies(this ContainerBuilder, string currentUserId, IEnumerable<Assembly> dataClassMapAssemblies, params DatabaseConfig[] configs) is the single integration point where the DI/composition layer, the data-access subsystem, and core framework services are wired together. A consuming application calls this from its own RegisterAppDependencies override (invoked during the program runner entry point).
| Field | Value |
|---|---|
| Operation ID | OP-WIN-005 |
| Trigger | Called once per DatabaseConfig instance from AutofacExtensions.RegisterCommonDependencies, itself called from a consuming application's RegisterAppDependencies override. |
| Inputs | currentUserId (non-null, enforced), optional dataClassMapAssemblies, params DatabaseConfig[] configs. |
| Outputs | Autofac registrations added to the supplied ContainerBuilder. |
| Primary components | AutofacExtensions.RegisterCommonDependencies, DatabaseConfig.RegisterUnitOfWorkFactories, DatabaseConfig.RegisterUnitOfWork |
| Entry point | Console\SAIF.Console\Console\AutofacExtensions.cs |
Steps¶
Enforce.ArgumentNotNull(currentUserId, "currentUserId")— throws ifcurrentUserIdis null (BR-WIN-013).- If
configs != null:DatabaseConfig.RegisterUnitOfWorkFactories(builder, dataClassMapAssemblies)registers three named,SingleInstanceIUnitOfWorkFactoryfactories: "oracle"→OracleUnitOfWorkFactory(new OracleConfigurationFactory(...))"oracleStateless"→OracleStatelessUnitOfWorkFactory(new OracleConfigurationFactory(...))"sqlSever"→SqlServerUnitOfWorkFactory(new SqlServerConfigurationFactory(...))(typo preserved verbatim from source)- Then, for each supplied
DatabaseConfig, callsx.RegisterUnitOfWork(builder)(step 3). - Each
DatabaseConfig.RegisterUnitOfWork(builder)registers, named byConfigNameand typedAs<IUnitOfWork>().As<IRepositoryFactory>(),InstancePerLifetimeScope, a factory delegate that: - Resolves the named
IUnitOfWorkFactory(via the subclass'sFactoryName— BR-WIN-015 forSqlServerConfig, BR-WIN-016 forOracleConfig). - Calls
.GetUnitOfWork(connectionString, showSql: ShowSql, batchSize: BatchSize), whereconnectionString = GetConnectionString(env, env.GetConfigSetting(EnvironmentConfigKey))(subclass-specific — Oracle usesDbConnectionManager.GetConnectionStringForInstance, SQL Server usesDbConnectionManager.GetConnectionStringForSqlServer). ServiceRegistrations.RegisterCoreServicesForWindows(builder, currentUserId)— external registration call (implementation not in this library).- Registers
WindowsEnvironmentServiceAs<IEnvironmentService>(),InstancePerLifetimeScope. - Registers
ConsoleLogServiceAs<IConsoleLogService>(),InstancePerLifetimeScope— this registration is the trigger for console log service discovery the first timeIConsoleLogServiceis resolved.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([RegisterCommonDependencies called]) --> Enforce[Enforce currentUserId not null]
Enforce --> ConfigsCheck{configs supplied?}
ConfigsCheck -->|Yes| Factories[Register oracle / oracleStateless / sqlSever factories]
Factories --> PerConfig[RegisterUnitOfWork per DatabaseConfig]
ConfigsCheck -->|No| Core[RegisterCoreServicesForWindows]
PerConfig --> Core
Core --> EnvSvc[Register WindowsEnvironmentService as IEnvironmentService]
EnvSvc --> LogSvc[Register ConsoleLogService as IConsoleLogService]
LogSvc --> Done([Registrations added to builder])
Failure and edge-case behavior¶
- A null
currentUserIdthrows before any registration is added to the container (BR-WIN-013). - No enforcement exists for a null/empty
DatabaseConfig.EnvironmentConfigKey— such a value is passed straight through toIEnvironmentService.GetConfigSetting, with the resulting behavior determined entirely by the externalIEnvironmentServiceimplementation.* WindowsEnvironmentServiceis registered unconditionally; a consuming application cannot override theIEnvironmentServiceimplementation without a subsequent overriding registration (last-registration-wins in Autofac).
Related documentation¶
Note: Statements marked with
*were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.
Sources¶
Console\SAIF.Console\Console\AutofacExtensions.csConsole\SAIF.Console\Console\DatabaseConfigs\DatabaseConfig.csConsole\SAIF.Console\Console\DatabaseConfigs\OracleConfig.csConsole\SAIF.Console\Console\DatabaseConfigs\SqlServerConfig.cs