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¶
Enforce.ArgumentNotNullonbuilderandapplication(BR-01).- Register MVC/Web API discovery from
application.Assembly:RegisterControllers,RegisterApiControllers,RegisterFilterProvider,RegisterWebApiFilterProvider(GlobalConfiguration.Configuration),RegisterModelBinders. The filter providers are what supply property injection toSaifAuthorizeAttributeandHandleExceptionAttribute.* - Call
ServiceRegistrations.RegisterCoreServicesForWeb(builder)— delegated toSAIF.Framework.Core; its registration list is not visible in this repository.** - Register
OracleUnitOfWorkFactory(new OracleConfigurationFactory(dataClassMapAssemblies))asIUnitOfWorkFactorynamed"oracle",SingleInstance. - Register
SqlServerUnitOfWorkFactory(new SqlServerConfigurationFactory(dataClassMapAssemblies))asIUnitOfWorkFactorynamed"sqlserver",SingleInstance. - Register
Repository<DataModel.Menu.BusinessOnlineMenuItem>over the namedNHibernateUnitOfWork"menu"asIRepository<DataModel.Menu.BusinessOnlineMenuItem>,InstancePerRequest. - Register the named
NHibernateUnitOfWork"menu"by resolving the"oracle"factory and callingGetUnitOfWork(DbConnectionManager.GetOracleConnectionString(IEnvironmentService, EnvironmentConfigKeys.OracleDatabase, "MENU")),InstancePerRequest(BR-31). - Register
MenuServiceasIMenuService,InstancePerRequest. - Register
WebContextServiceasIWebContextService,InstancePerRequest. - Register
WebEnvironmentService(new HttpContextWrapper(HttpContext.Current))asIEnvironmentService,SingleInstance. The singleton lifetime capturesHttpContext.Currentat 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.
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. Statements marked with**could not be confirmed; treat as unknown until verified.
Sources¶
src/Web.Mvc/Extensions/AutofacExtensions.cs