It takes quite an effort to instrument/inject some of the Steeltoe features in full framework app. SteeltoeOSS has Autofac extensions for full framework to abstract away that effort. But there are no Unity extensions available. Sample apps in steeltoe-unity-samples
git repo illustrate how to use Steeltoe features with less effort when using Unity for IoC services.
How it works? - configure and add services to Microsoft DI container and load them into Unity container. So you can leverage Unity IoC in your apps the same way you do and can inject Steeltoe interfaces. Unity container will resolve them without any issues.
Note: Create/upgrade your app to target .Net Framework 4.6.1 or above, since we are making use of .Net Standard libraries
Get Unity.Microsoft.DependencyInjection nuget
Add services to Microsoft DI container. Refer to ApplicationConfig.cs
Use DiscoveryConfig.cs to register/fetch your app in/from Eureka server
Use ManagementConfig.cs to add Cloud Foundry management endpoints and healthchecks
Register and build service provider in Application_Start() method in Global.asax.cs
// register microsoft & steeltoe services
ApplicationConfig.Register(Environment.GetEnvironmentVariable("ASPNET_ENVIRONMENT") ?? "Development");
// build service provider for unity container
ApplicationConfig.BuildServiceProvider(UnityConfig.Container);
BuildServiceProvider(UnityConfig.Container) method loads registrations from Microsoft container to Unity container
public static void BuildServiceProvider(IUnityContainer container)
{
// add services to unity container. piggy backing on Unity.Microsoft.DependencyInjection extensions
container.BuildServiceProvider(_services);
}
Refer to Global.asax.cs to start and stop Discovery client
src/FortuneTeller/Fortune-Teller-Service
- use config server, connect to a MS SQL database on Azure, use Discovery client, add health managementsrc/FortuneTeller/Fortune-Teller-UI
- use config server, connect to Fortune-Teller-Service using Discovery client, add health management, connect to Redis server on Cloud Foundry