Getting Started

Creating a New Project

The first thing you need to do, obviously, is to download the framework installer from this site. Once this is done, you can find application templates in your Visual Studio’s New Project dialog. In this tutorial we will start off from the “ShellFactory Empty Application” template, in order to explain every aspect of the framework.

image

Project Structure

Once you have created a new project based upon this template, you will be presented with this project structure:

image

As you can see, the default structure is divided into three assemblies:

  • Infrastructure
    This assembly should contain all code which is shared between all modules of your project, like for application services or extensibility code.
  • Core Module
    Contains the implementation of the services defined in the infrastructure assembly, as well as the basic functionality of your application. It is suggested that even the main view is implemented here, to keep the shell assembly as minimal as possible, but it is not a requirement.
  • Shell
    This assembly functions as the startup point of your application (the application executable). It is suggested that this is kept as minimal as possible to keep with the modularity principles the ShellFactory framework is based upon, but it is not a requirement.

Application Services

An application service as defined by the ShellFactory framework is an object which provides functionality as defined by an interface, and available via the ServiceContainer static class, which you will find in the Creventive.Wpf.ShellFactory.Services namespace. For this tutorial we will be creating a simplified settings service, just to demonstrate the concept.

Start off by adding a new interface in your Infrastructure assembly. We’ll just put it into the root namespace for the sake of simplicity. Then we add some methods to it.

using System.Linq;

namespace GettingStarted.Infrastructure
{
    /// <summary>
    /// Provides application settings to all modules.
    /// </summary>
    public interface ISettingsService
    {
        /// <summary>
        /// Gets the value of the setting with the specified key.
        /// </summary>
        /// <param name="settingsKey">The settings key.</param>
        /// <returns></returns>
        string GetValue(string settingsKey);

        /// <summary>
        /// Sets the value of the setting with the specified key.
        /// </summary>
        /// <param name="settingsKey">The settings key.</param>
        /// <param name="value">The value.</param>
        void SetValue(string settingsKey, string value);
    }
}

Ok, so it’s not very sophisticated, but it’ll have to do for this tutorial. The goal is to provide a single point of entry for settings, enabling you to change the implementation of the service without changing any code in any module.

Next we’ll want to create our service implementation. Personally I would define this as a core service, so we’ll implement it in our Core module. I chose to put this service in a Settings namespace.

using System;
using System.Linq;
using Creventive.Wpf.ShellFactory.Services;
using GettingStarted.Infrastructure;

[assembly: Service(typeof(ISettingsService), typeof(GettingStarted.Modules.Core.Settings.SettingsService))]

namespace GettingStarted.Modules.Core.Settings
{
    internal class SettingsService: ISettingsService
    {
        public string GetValue(string settingsKey)
        {
            throw new NotImplementedException();
        }

        public void SetValue(string settingsKey, string value)
        {
            throw new NotImplementedException();
        }
    }
}

The line to notice here is this one:

[assembly: Service(typeof(ISettingsService), typeof(GettingStarted.Modules.Core.Settings.SettingsService))]

This tells the ShellFactory Framework that the type specified by the second argument is the implementation of the service for the type specified by the first argument. In other words: Every time a module calls

ServiceContainer.Default.GetService<ISettingsService>();

you will get an instance of the object we just created.

To be continued…

Last edited Apr 3, 2011 at 3:13 PM by Mantaray, version 5

Comments

No comments yet.