Web API Tutorials Part 3 : Translation Abstraction

There’s a famous quote in the world of Software Development:

“We can solve any problem by introducing an extra level of indirection.”

In my experience, this is almost certainly correct, this post will see us adding in an additional layer of Abstraction to allow us to simplify our Controller(s) and manage our Dependencies in a more straightforward manner.

Outcome

Last post saw us implement our Translation PCL into our Web API using Dependency Injection.  The problem is that our ITranslator Interface only handles a single Translator Implementation, such that when we inject from our Container we can’t currently translate more than one direction.  We’ll look into the why’s shortly, but by the end of the post we will have created :

  • ITranslatorService Interface;
  • TranslatorService Implementation and Unit Tests.

Continue reading “Web API Tutorials Part 3 : Translation Abstraction”

Eager Instantiation of ViewModels with MVVM Light Messaging

Dependency registration in SimpleIoc, by default uses Lazy Instantiation, meaning the object won’t be created until it is requested, in this case, via the property on the ViewModelLocator class.

Due to configuring subscription of a message type in the Constructors of my ViewModels in MVVM Light I recently came across a situation whereby messages were being published prior to them having been subscribed to, meaning that the messages disappeared into the void unhandled.  The ViewModels relating to the pages I had navigated to were available in the ServiceLocator, but the pages that I hadn’t navigated to were not being instantiated.

Continue reading “Eager Instantiation of ViewModels with MVVM Light Messaging”

Universal App Tutorials Part 10 : MVVM Light NavigationService

Despite the rise in popularity of Single Page Applications (SPAs) and supporting frameworks like Angular in the Web Development world, it might be nice if we had more than one page in our app, or at least had the option to.  Our app so far is contained within a single page, MainPage.xaml.  A common pattern is to have different pages for Settings or Publisher contact information.  Navigation has moved on since Windows Phone 7.5 when it was URI based, we will look at how it now works with Universal Apps with typing and the MVVM Light implementation of INavigationService. Continue reading “Universal App Tutorials Part 10 : MVVM Light NavigationService”

Morse Coder Part 6 : Handling Application Settings – Explicitly Typed and Blendable

In Universal Apps the ApplicationData.LocalSettings Property in the Windows.Storage namespace can be used to persist Application Settings. It stores your data into an ApplicationDataContainer, which ultimately provides a wrapper around a Dictionary<string, object> and manages the persistence around the application lifecycle for you.

Outcome

It can be helpful to be able to reference your Application Settings without needing to cast them from the object stored in the dictionary to the relevant type before consumption every time. We’ll look at wrapping an interface around our Application Settings, giving us the object types, along with the ability to be able to use application settings in our UI at design time.

Continue reading “Morse Coder Part 6 : Handling Application Settings – Explicitly Typed and Blendable”

Morse Coder Part 4 : Dependency Injection with MVVM Light SimpleIoc

To date, we have a functional, but basic set of Windows Phone and Windows Store applications which can translate Alphabetical Input to Morse Code. One of the key tenets of MVVM Light is the ability to inject design time services or functionality to provide a better design experience. We need somewhere to store our Application Settings, along with a means of setting and retrieving them, we won’t cover the implementation of this, but we will cover the creation of our interface and the implementation of a design time settings class.

Outcome

By the end of this post we will have, at design time, the ability to manipulate a settings class to be used with the designer in Visual Studio, or through Expression Blend. This will be done via an application settings interface detailing what data we need to store and of course what type it needs to be. As we are targeting multiple platforms, the interface, in a future post will be implemented to provide the storage of our settings per operating system.

One of the main benefits of using Dependency Injection to achieve this is that the implementation of our ViewModel is not concerned with where it retrieves information from and doesn’t need to make decisions depending on which context it is being ran in, this moves us closer to alignment with the Single Responsibility Principle.

Continue reading “Morse Coder Part 4 : Dependency Injection with MVVM Light SimpleIoc”