c# - Lazy initialization error with parameter -
i coding mvc internet application , have question in regards lazy initialization.
here working code before lazy initialization:
declaration:
private validationservice validationservice;
initialization:
validationservice = new validationservice(genericmultiplerepository);
here code trying:
declaration:
private lazy<validationservice> validationservice;
initialization:
validationservice = new lazy<validationservice>(genericmultiplerepository);
here error:
error 125 best overloaded method match 'system.lazy.lazy(system.threading.lazythreadsafetymode)' has invalid arguments
i have looked @ lazy<t> constructor documentation
, don't see wrong.
the constructor of lazy expects func
returns validationservice
type specified:
validationservice = new lazy<validationservice> ( () => new validationservice(genericmultiplerepository) );
that equivalent to:
validationservice = new lazy<validationservice> ( somemethod ); private validationservice somemethod() { return new validationservice(this.genericmultiplerepository); }
note can't pass parameter genericmultiplerepository
inferred using lambda expression.
Comments
Post a Comment