In all previous code, the simple IoC system worked using generic interfaces and generic extension methods.
So, for example, to import a service like IMyService, then the user would write code like:
public class TwitterViewModel : MvxViewModel , IMvxServiceConsumer<ITwitterSearchProvider> { private ITwitterSearchProvider TwitterSearchProvider { get { return this.GetService<ITwitterSearchProvider>(); } } }This has some duplication of the generic target - and it can make class declarations quite long winded... To make the code 'cleaner', in vNext, I've removed the generic part from the interface - so now code like this will work:
public class TwitterViewModel : MvxViewModel , IMvxServiceConsumer { private ITwitterSearchProvider TwitterSearchProvider { get { return this.GetService<ITwitterSearchProvider>(); } } }
Presumably this means that you now only need to use one ",IMvxServiceConsumer" to consume as many services as you like within the class? Which is great :)
ReplyDeleteYes - and because MvxViewModel inherits from IMvxServiceConsumer, then it means that all ViewModels can automatically use the GetService extension methods :)
ReplyDeleteThis does kind of mean that we lose some declarative meaning from our classes... but it does make the IoC quicker and easier to use... so I think it's a WIN :)