'Catel.IoC.IServiceLocator' does not contain a definition for 'Instance'

339 Views Asked by At

I'm quite new to .NET development and Catel but is working on a project to learn it. At the moment the original developer is not present so I'll try my luck here instead.

To implement Undo/Redo the Memento Pattern support of Catel seems great so giving it a try but I have problems getting an instance of the MementoService. When I do in my ViewModel: var mementoService = ServiceLocator.Instance.ResolveType<IMementoService>(); I get: 'Catel.IoC.IServiceLocator' does not contain a definition for 'Instance' and no extension method 'Instance' accepting a first argument of type 'Catel.IoC.IServiceLocator' could be found (are you missing a using directive or an assembly reference?)

I have noticed that when I do the same in my Model though I do not get this problem. Seems strange that I would need different ways of getting an instance of the service depending on where I try to get it.

I do not understand what I'm doing wrong. The NuGet Package Manager Console tells me I have Catel.Extensions.Memento 3.7 installed as well as Catel.Core, Catel.MVVM and Catel.Extensions.Controls 3.7. I'm using Visual Studio 2013 with .NET 4.0.

1

There are 1 best solutions below

8
On BEST ANSWER

The interface does not have an Instance property, and it is obsolete.

You should use this:

1) In a static context:

Catel.IoC.ServiceLocator.Default

2) In a non-static context (takes care of scopes automatically):

var serviceLocator = this.GetServiceLocator();