dependency injection - What's the equivalent of the DictionaryAdapterFactory of Windsor in Ninject? -
i'm trying reproduce below configuration of windsor on ninject. know ninject has factory extension it's far away dictionary adapter windsor have.
windsorcontainer container = new windsorcontainer(); container.addfacility<castle.facilities.factorysupport.factorysupportfacility>(); container.register( component.for<iapplicationsettings>().usingfactorymethod( () => new dictionaryadapterfactory() .getadapter<iapplicationsettings>(configurationmanager.appsettings)));
does know factory extension ninject dictionary adaptation?
the factory extension allows provide own iinstanceprovider
. can use return values config:
class program { static void main(string[] args) { var kernel = new standardkernel(); kernel.bind<iapplicationsettings>().tofactory(() => new appsettingprovider()); var settings = kernel.get<iapplicationsettings>(); console.writeline("one: " + settings.one); } } public interface iapplicationsettings { string 1 { get; } int 2 { get; } bool 3 { get; } } public class appsettingprovider : ninject.extensions.factory.iinstanceprovider { public object getinstance(iinstanceresolver instanceresolver, methodinfo methodinfo, object[] arguments) { string key = methodinfo.name; if (key.startswith("get_")) key = key.substring(4); string value = configurationmanager.appsettings[key]; return convert.changetype(value, methodinfo.returntype); } }
Comments
Post a Comment