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

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -