i'm trying adjust wp8 project self made mvvm implementation mvvm light.
the application compiles without errors, when open mainpage.xaml in expression blend, error:
class project.services.inavigationservice registered. app.xaml
my viewmodellocator.cs:
/// <summary> /// initializes new instance of viewmodellocator class. /// </summary> public viewmodellocator() { servicelocator.setlocatorprovider(() => simpleioc.default); if (viewmodelbase.isindesignmodestatic) { } else { if (!simpleioc.default.isregistered<inavigationservice>()) { simpleioc.default.register<inavigationservice>(() => new navigationservice()); } } simpleioc.default.register<mainpage>(); simpleioc.default.register<settingseditviewmodel>(); }
as can see code comment, i've tried fix supposed here, i'm still getting error in blend. there no other place left register inavigationservice, problem?
any ideas? :)
i had same issue, , seems visual studio issue in combination xaml-designer, static factories/locators , design-time creation of objects. however: solutions following:
register without factory (not recommended)
simpleioc.default.register<inavigationservice>();
or if want use factory, unregister before registering factory
simpleioc.default.unregister<inavigationservice>();
simpleioc.default.register<inavigationservice>(() => new navigationservice());
prevent viewmodellocator being created more once designer/blend making constructor static
static viewmodellocator() { ... }
the error cumbersome happen in scenario: create objects during design-time (the viewmodellocator
within app.xaml probably) , whenever change in code, compiler triggered , viewmodellocator gets re-created without ever unregistering services. therefore complain in factory has been registered. in theory, when registering classes without factories multiple times, there should error as-well.
Comments
Post a Comment