Application Integration

IoC.Configuration now supports seamless integration with various .NET application types by allowing the application’s native dependency injection container to use IoC.Configuration for resolving services.

This integration is achieved through the use of the IIntegratesWithHostBuilder interface and specialized extension libraries for different frameworks. By hooking into the application’s host building process, IoC.Configuration can manage service registrations and resolution transparently.

Overview

The integration typically involves:

  1. Initializing the IoC.Configuration.DiContainerBuilder.DiContainerBuilder.

  2. Configuring the file-based dependency injection.

  3. Using the WithHostBuilder method to provide an implementation of IoC.Configuration.DiContainerBuilder.IApplicationHostBuilder.

    Note

    The default implementation IoC.Configuration.DiContainerBuilder.ApplicationHostBuilder works in some frameworks, such as in WinUI3 applications, while some other frameworks such as ASP.NET and Maui require custom implementations provided in nuget packages IoC.Configuration.AspNet and IoC.Configuration.Maui. The source code of these packages can be found at these links: IoC.Configuration.AspNet, IoC.Configuration.Maui.

  4. Registering modules and starting the container.

Currently, this feature is primarily supported for file-based configurations when DI manager specified in iocConfiguration/diManagers targets Autofac DI manager. In other words, the new interfaces for supporting application integration are implemented in IoC.Configuration.Autofac only at this point. The implementations of these interfaces in IoC.Configuration.Ninject currently throw NotImplementedException exception. Support for Ninject will be added later when there is demand, or when Ninject library or any of its extensions implements the Microsoft.Extensions.DependencyInjection.IServiceProviderFactory<TContainerBuilder>.

Note

Code based configuration support requires very little effort, however was not yet implemented. Will be implemented in the future if there is demand.

Supported Frameworks

Note

Other frameworks might be supported too (for example UWP) by using the default implementation IoC.Configuration.DiContainerBuilder.ApplicationHostBuilder of interface IoC.Configuration.DiContainerBuilder.IApplicationHostBuilder, however no testing was done yet.

  • ASP.NET Core: Integration with the web host to resolve controllers and other services via IoC.Configuration. Refer to the example in project WebApiDemo.csproj and related projects in ApplicationIntegrationDemos/ASP.NET.WebApi.

  • .NET MAUI: Integration with the Maui app builder. Refer to the example in project MauiDemo.csproj and related projects in ApplicationIntegrationDemos/Maui.

  • WinUI 3: Integration with WinUI 3 application hosting. Refer to the example in project WinUI3Demo.csproj and related projects in ApplicationIntegrationDemos/WinUI3.