c# - Autofac and WebForms - passing non-constant parameters, resolved parameters? -
i'm getting started autofac , have following code:
public class _default : system.web.ui.page, iuserinformationprovider { protected void page_load(object sender, system.eventargs e) { controllerfactory cf; using (scope == ((global_asax)this.context.applicationinstance).containerprovider.applicationcontainer.beginlifetimescope()) { cf = scope.resolve<icontrollerfactory>(); // <-- love pass "this" somewhere here, how??? } } }
controllerfactory defined below , takes iuserinformationprovider interface. pass instance of webform parameter resolve icontrollerfactory.
public class controllerfactory : icontrollerfactory { protected iuserinformationprovider _userinformation; public controllerfactory(iuserinformationprovider userinformation) { _userinformation = userinformation; } }
looking through documentation, see there 3 parameter types (named, typed, resolved), first 2 take constant values. seems resolved parameters way go, i'm kind of lost how implement it, or if that's right strategy. , builder.register like?
you can pass additional parameter not when registering when resolving type.
the resolvedparameter
can used if iuserinformationprovider
registered in container won't work in case.
however can use namedparameter
need pass parameter name have used in contrustor "userinformation"
, value this
:
cf = scope.resolve<icontrollerfactory>( new namedparameter("userinformation", this));
or can use typedparameter
need pass type of parameter in case typeof(iuserinformationprovider)
, again value of this
:
cf = scope.resolve<icontrollerfactory>( new typedparameter(typeof(iuserinformationprovider), this));
if looking general guide how can integrate webforms autofac can start documentation
Comments
Post a Comment