Click here to Skip to main content
15,843,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using Asp.net webapi with c# framework 4.7 with those I am trying to handle the apseeting.json file using Calabonga.Configuration package

I don't know how can I register class instance that depends on multiple interfaces in unity container. I read the article where someone registe it with autofac
here is AppSetting class

public class ApplicationSettings
{
    public string AdministrtorEmail { get; set; }
    public int DeafultPageSize { get; set; }
    public string ApplicationName { get; set; }
    public string ApplicationDomain { get; set; }
    public string SecretKey { get; set; }
}


SettingManager
public class SettingsManager : Configuration<ApplicationSettings>
{
    public SettingsManager(IConfigSerializer serializer, ICacheService cacheService)
        : base(serializer, cacheService)
    {
    }
}


so at the end there is a dependency injection container below I paste the code that works perfectly with autofac but someone knows equal code replacement using unity container?? I tried to replace this code but it did not work with SettingsManager class

public static class DependencyContainer
{
    public static void Initialize()
    {
        var builder = new ContainerBuilder();
        builder.RegisterControllers(Assembly.GetExecutingAssembly());

        // Calabonga.Configuration injections
        builder.RegisterType<CacheService>().As<ICacheService>(); // alternative code in unity
        builder.RegisterType<JsonConfigSerializer>().As<IConfigSerializer>(); // alternative code in unity
        builder.RegisterType<SettingsManager>().AsSelf(); // alternative code in unity container

        var container = builder.Build();
        DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
    }
}


What I have tried:

I tried something like this

// Calabonga.Configuration injections
            container.RegisterType<ICacheService, CacheService>(new HierarchicalLifetimeManager());
            container.RegisterType<IConfigSerializer, JsonConfigSerializer>(new HierarchicalLifetimeManager());
            container.RegisterType<SettingsManager>();
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900