AppSurface Search
API Reference

Autofac

Type

AppSurfaceAutofacExtensions

Source

Provides extension methods for Autofac's ContainerBuilder to simplify common registrations.

Remarks

These helpers are convenience wrappers for assembly-scoped reflection scanning. Prefer explicit Autofac registration when ordering matters, multiple implementations need different lifetimes, startup performance is sensitive, or AOT/linker trimming must preserve only known types.

Method

RegisterImplementations

2 overloads
IRegistrationBuilder<object, ScanningActivatorData, DynamicRegistrationStyle> RegisterImplementations<TInterface>(this ContainerBuilder builder)

Registers all non-abstract class implementations of the specified interface type found in the interface's assembly.

Type parameters

  • TInterface
    The interface type to scan for implementations of.

Parameters

  • builder
    The container builder.

Returns

A registration builder for the scanned types.

Remarks

This method scans only the assembly that declares TInterface and registers concrete, non-abstract assignable classes as TInterface services. It returns Autofac's IRegistrationBuilder{TLimit,TActivatorData,TRegistrationStyle} so callers can add lifetime, ownership, and metadata configuration. Use this helper when one interface owns a small assembly-local plugin surface and interface resolution is the intended contract. Prefer explicit registrations when implementations cross assemblies, require different service interfaces, need distinct lifetimes, or must be linker/AOT-friendly. Reflection scanning recovers from partial type-load failures by registering successfully loaded types only, so missing optional dependencies can still hide implementations that failed to load.

IRegistrationBuilder<object, ScanningActivatorData, DynamicRegistrationStyle> RegisterImplementations<TInterface>(this ContainerBuilder builder, Func<Assembly, Type[]> getTypes)

Registers implementations of TInterface using a caller-provided assembly type loader.

Type parameters

  • TInterface
    The interface type to scan for implementations of.

Parameters

  • builder
    The container builder.
  • getTypes
    Type loader for the assembly that declares TInterface .

Returns

A registration builder for the scanned types.

Exceptions

  • InvalidOperationException
    Thrown when getTypes completes successfully but returns null .

Remarks

This internal seam exists so tests can verify partial-load recovery without creating a broken fixture assembly. The getTypes delegate must return a non-null array for successful loads. If it throws ReflectionTypeLoadException , successfully loaded non-null entries from ReflectionTypeLoadException.Types are still registered and failed entries are ignored.

Method

GetLoadableTypes

IEnumerable<Type> GetLoadableTypes(Assembly assembly, Func<Assembly, Type[]> getTypes)

Gets all loadable types from an assembly while tolerating partial reflection-load failures.

Parameters

  • assembly
    The assembly being scanned.
  • getTypes
    The delegate used to load the assembly's type array.

Returns

All loaded types, or the non-null subset from ReflectionTypeLoadException.Types .

Exceptions

  • InvalidOperationException
    Thrown when getTypes completes successfully but returns null .
Type

AppSurfaceAutofacHostModule

Source

A base module that integrates Autofac into the AppSurface host lifecycle.

Type

AppSurfaceAutofacModule

Source

An Autofac Module wrapper that also participates in AppSurface module discovery.

Remarks

AppSurfaceAutofacModule implements IAppSurfaceModule so Autofac-backed modules can be discovered with the rest of the AppSurface graph. Put Autofac registrations in normal Autofac module methods such as Module.Load(ContainerBuilder) ; ConfigureServices is intentionally a no-op for interface compatibility. Override RegisterDependentModules when this module requires other AppSurface modules. Pitfall: Autofac registration ordering and module dependencies still matter, so do not expect ConfigureServices to bridge Microsoft DI registrations into Autofac.

Method

ConfigureServices

void ConfigureServices(StartupContext context, IServiceCollection services)

Intentionally does not register Microsoft DI services for this Autofac module.

Parameters

  • context
    The current startup context.
  • services
    The Microsoft DI service collection, unused by this module.

Remarks

Use Autofac's Module.Load(ContainerBuilder) for registrations. This method exists only to satisfy IAppSurfaceModule .

Method

RegisterDependentModules

void RegisterDependentModules(ModuleDependencyBuilder builder)

Registers AppSurface module dependencies required before this Autofac module is used.

Parameters

  • builder
    The module dependency builder used to declare prerequisites.