c# - How to create a static instance of a dependency injected class? -
i've defined class takes repository instance sole constructor argument. , created static instance of class, mainviewmodel
constructor arguments need specified.
issue:
in order specify required arguments, added irepository argument expected in static instance of mainvm class.
this didn't work expected compiler throwing following errors result of this:
using generic type 'parkingtagpicker.dal.irepository<t>' requires 1 type arguments parkingtagpicker.models.zone' 'type' used 'variable' name 'zonedataservice' not exist in current context
from looking @ errors seems irepository being supplied correct zone
type.
does know how correctly define constructor args in situation?
mainviewmodel:
//irepository instance zone type arg //(zone model class) private irepository<zone> _zonedataservice; public mainviewmodel(irepository<zone> zonedataservice) { this._zonedataservice = zonedataservice; }
app.xaml.cs:
/// <summary> /// static viewmodel used views bind against. /// </summary> /// <returns>the mainviewmodel object.</returns> public static mainviewmodel viewmodel { { // delay creation of view model until necessary if (viewmodel == null) viewmodel = new mainviewmodel(irepository<zone> zonedataservice); return viewmodel; } }
Comments
Post a Comment