Skip to content

Register common web dependencies

Wire MVC/Web API discovery, NHibernate unit-of-work factories, and menu/web-context/environment services into the consumer's Autofac container. Trigger: Consuming application startup composition*.

Field Value
Operation ID OP-14
Trigger Consuming application startup composition*
Inputs ContainerBuilder, a type from the application assembly, optional extra NHibernate class-map assemblies
Outputs Registrations added to the container; the caller still owns Build()
Primary components AutofacExtensions.RegisterCommonDependencies(ContainerBuilder, Type application, IEnumerable<Assembly> dataClassMapAssemblies = null)
Entry point src/Web.Mvc/Extensions/AutofacExtensions.cs

Steps

  1. Enforce.ArgumentNotNull on builder and application (BR-01).
  2. Register MVC/Web API discovery from application.Assembly: RegisterControllers, RegisterApiControllers, RegisterFilterProvider, RegisterWebApiFilterProvider(GlobalConfiguration.Configuration), RegisterModelBinders. The filter providers are what supply property injection to SaifAuthorizeAttribute and HandleExceptionAttribute.*
  3. Call ServiceRegistrations.RegisterCoreServicesForWeb(builder) — delegated to SAIF.Framework.Core; its registration list is not visible in this repository.**
  4. Register OracleUnitOfWorkFactory(new OracleConfigurationFactory(dataClassMapAssemblies)) as IUnitOfWorkFactory named "oracle", SingleInstance.
  5. Register SqlServerUnitOfWorkFactory(new SqlServerConfigurationFactory(dataClassMapAssemblies)) as IUnitOfWorkFactory named "sqlserver", SingleInstance.
  6. Register Repository<DataModel.Menu.BusinessOnlineMenuItem> over the named NHibernateUnitOfWork "menu" as IRepository<DataModel.Menu.BusinessOnlineMenuItem>, InstancePerRequest.
  7. Register the named NHibernateUnitOfWork "menu" by resolving the "oracle" factory and calling GetUnitOfWork(DbConnectionManager.GetOracleConnectionString(IEnvironmentService, EnvironmentConfigKeys.OracleDatabase, "MENU")), InstancePerRequest (BR-31).
  8. Register MenuService as IMenuService, InstancePerRequest.
  9. Register WebContextService as IWebContextService, InstancePerRequest.
  10. Register WebEnvironmentService(new HttpContextWrapper(HttpContext.Current)) as IEnvironmentService, SingleInstance. The singleton lifetime captures HttpContext.Current at first resolution.*

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([Consuming app startup])
    Guard[Guard builder/application]
    MvcReg[Register MVC/Web API discovery]
    Core[RegisterCoreServicesForWeb]
    UoW[Register oracle/sqlserver unit-of-work factories]
    Repo[Register menu repository and unit of work]
    Svc["Register MenuService,<br>WebContextService,<br>WebEnvironmentService"]
    EndOk(["Registrations added; caller calls Build"])
    Start --> Guard
    Guard --> MvcReg
    MvcReg --> Core
    Core --> UoW
    UoW --> Repo
    Repo --> Svc
    Svc --> EndOk

Failure and edge-case behavior

  • No unexpected failure paths beyond argument-guard exceptions and delegated dependency behavior were identified for this operation.

Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts. Statements marked with ** could not be confirmed; treat as unknown until verified.

Sources

  • src/Web.Mvc/Extensions/AutofacExtensions.cs