I'm trying to make an aspnet core project using Unity.container.
My problem is to load the unity.config, so I'm trying make the project use the web.config
this is my startup.
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>().UseUnityServiceProvider(GetContainer());
private static IUnityContainer GetContainer()
{
var unitySection = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
Dictionary<string, IUnityContainer> containers = new Dictionary<string, IUnityContainer>();
InitiateContainers(unitySection, containers);
return containers.Values.First();
}
internal const string DefaultContainerName = "Default";
internal static void InitiateContainers(UnityConfigurationSection unitySection, IDictionary<string, IUnityContainer> containers)
{
foreach (var element in unitySection.Containers)
{
string name = string.IsNullOrEmpty(element.Name) ? DefaultContainerName : element.Name;
if (!containers.ContainsKey(name))
{
containers.Add(name, new UnityContainer());
}
unitySection.Configure(containers[name], element.Name);
}
}
But the variable "unitySection" is always null.
How can I make the aspnet core app load the web.config file?
Do I need to import another nuget package?