c# - Castle Windsor web.config parameters -
i transfer windor installer in web.config of webapplication, need pass parameter static attribute of class. there's example:
// (namespace web) public void install(iwindsorcontainer container, iconfigurationstore store) { container.register( component.for(typeof(irepository)) .implementedby(typeof(repository<myctx>)) .dependson(dependency.onvalue("store", mvcapplication.globalstore)) .lifestyleperwebrequest() ); }
my actual web.config:
<components> <component service="core.business.irepository, core" type="ef.business.repository, ef" lifestyle="perwebrequest"> <parameters> <store>web.mvcappltication.globalstore ???</store> </parameters> </component> </components>
i concluded has defined in code. therefore decided way of create facility.
my new code:
web.config
<component service="core.business.irepository, core" type="ef.business.repository`1[[ef.creationcontext, nodiink.arcow.data.ef]], ef" lifestyle="perwebrequest"> </component>
dependencyresolver.cs
public class runtimedatasupportfacility : abstractfacility { protected override void init() { kernel.resolver.addsubresolver(new runtimedatadependencyresolver()); } } public class runtimedatadependencyresolver : isubdependencyresolver { private type[] acceptedtypes = new[] { typeof(idictionary<string, object>) }; public object resolve(creationcontext context, isubdependencyresolver contexthandlerresolver, componentmodel model, dependencymodel dependency) { if (referenceequals(dependency.targettype, acceptedtypes[0])) // typeof(idictionary<string, object> return mvcapplication.globalstore; return null; } public bool canresolve(creationcontext context, isubdependencyresolver contexthandlerresolver, componentmodel model, dependencymodel dependency) { if (acceptedtypes.any(t => referenceequals(t, dependency.targettype))) return true; return false; } }
and on global.asax.application_start():
container = new windsorcontainer() .addfacility<runtimedatasupportfacility>() // new code .install(configuration.fromappconfig());
Comments
Post a Comment