kick it on DotNetKicks.com   Shout it  

MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Source Code

Now that we’ve seen the View-Model in Part 5, how do we wire up the View-Model to the View? As any developer worth his salt would say, “it depends” (I’m trying to raise my worth to at least the value of salt ;) ).

Inversion of Control

First, let me define a few things. First, Inversion of Control is a pattern wherein creation of objects is delegated in an effort to simplify instantiation and/or defer it until runtime. Huh? Inversion of Control is a means of programming against interfaces. Your classes reference interfaces at design-time and then delegate the creation of the concrete classes to a single component or service. The result is you now have a only a single dependency – the “Container” – instead of a complex hierarchy of dependencies:

public class ServiceA() {
    public ServiceA(){ //... }
}
public class ServiceB() {
    public ServiceB(ServiceA, ServiceD){ //... }
}
public class ServiceC(ServiceA) {
    public ServiceC(){ //... }
}
public class ServiceD(ServiceA) {
    public ServiceD(){ //... }
}
 
public class Consumer {
    private ServiceB m_ServiceB;
    private ServiceC m_ServiceC;
    
    public Consumer() {
            ServiceA serviceA = new ServiceA();
            ServiceD serviceD = new ServiceD(serviceA);
            
            m_ServiceB = new ServiceB(serviceA, serviceD);
            m_ServiceC = new ServiceC(serviceA);
    }
}

The example above is not uncommon. Not only is it difficult to test, but if any of the classes require a change in constructor parameters or you want to change which service you’re referencing you’ve got to clean up every consumer class which uses the service you just changed. We’re looking at a high level of complexity and a very brittle implementation.

Most often Inversion of Control uses an object called a “Container” which is responsible for building these dependency hierarchies. The Container allows you to defer the creation of concrete classes until runtime. At some point before your class is instantiated, the Container is configured – most often either in your startup process or in a config file – with the mappings between your interfaces and the concrete implementations of your classes. Then when you need to get a reference to the concrete implementation of an interface or just create a new instance of a standard class you use the Container to wire everything up. For example, given the example above you can do either of the following:

   1: ServiceB m_ServiceB = Container.Resolve<ServiceB>();    // Create a new instance of a concrete class
   2: ISomeInterface m_SomeObject = Container.Resolve<ISomeInterface>(); // get a concrete instance of an interface

The first example may have you saying why use Container.Resolve<ServiceB>() instead of new ServiceB()? Well, given the definitions above, you’d actually need to do this:

ServiceA serviceA = new ServiceA;
ServiceD serviceD = new ServiceD;
ServiceB m_ServiceB = new ServiceB(serviceA, serviceD);

Using the Container is much cleaner. As for line 2, you really see the power of IoC where your code isn’t tied to any concrete implementation at all. This makes testing very simple and your code becomes very, very flexible.

Dependency Injection

Here’s a term around which there can be much confusion. It seems at times that it is synonymous with Inversion of Control (IoC), a term I have used some here in this series. It is true you don’t often see one without the other, but they are not the same.

Dependency Injection refers explicitly to the way you use IoC. Constructor Injection is the form of Dependency Injection you will see used in Prism. Other forms of Dependency Injection are Setter Injection and Interface Injection. I really don’t use these and so instead of floundering for when and how to use them I’ll refer you to Martin Fowler for more on these alternative forms of Dependency Injection.

public class ServiceA() : InterfaceA {
    public ServiceA(){ //... }
}
public class ServiceB() : InterfaceB {
    public ServiceB(InterfaceA, InterfaceD){ //... }
}
public class ServiceC(InterfaceA) : InterfaceC {
    public ServiceC(){ //... }
}
public class ServiceD(InterfaceA) : InterfaceD {
    public ServiceD(){ //... }
}
 
public class Consumer {
    private InterfaceB m_ServiceB;
    private InterfaceC m_ServiceC;
    
    public Consumer(InterfaceB, InterfaceC) {
            m_ServiceB = InterfaceB;
            m_ServiceC = InterfaceC;
    }
}

In this last example all the services implement interfaces and our consumer then accepts those interfaces as arguments to the constructor. In order to call Container.Resolve<Consumer>() we need to register our services with the container. You can do this either in your Bootstrapper or an IModule implementation like this:

Container.RegisterType<InterfaceA, ServiceA>();
Container.RegisterType<InterfaceB, ServiceB>();
Container.RegisterType<InterfaceC, ServiceC>();
Container.RegisterType<InterfaceD, ServiceD>();

Now you can create an instance of the Consumer class anywhere in your application with a single line of code. Also, when you test Consumer you can replace the actual implementation of the services with mock versions which allow you to test Consumer in isolation.

Dependency Injection with Prism

So how do we use Dependency Injection in a Prism application? It’s easy, here’s how:

EditorView.xaml.cs (code behind)

using System.Windows.Controls;
using CodeCamp.Common.ViewModel;
 
namespace CodeCamp.Editor
{
    public partial class EditorView : UserControl
    {
        public EditorView(EditorViewModel model)
        {
            InitializeComponent();
 
            this.DataContext = model;
        }
    }
}

EditorModule.cs

using CodeCamp.Common.ViewModel;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;
 
namespace CodeCamp.Editor
{
    public class EditorModule : IModule
    {
        private IRegionManager m_Manager;
 
        public EditorModule(IRegionManager manager)
        {
            m_Manager = manager;
        }
 
        #region IModule Members
 
        public void Initialize()
        {
            m_Manager.RegisterViewWithRegion("MainRegion", typeof(EditorView));
        }
 
        #endregion
    }
}

You should recognize the code in EditorModule.cs from part 4 of this series. Here we’re not doing anything but telling Prism to load EditorView into the MainRegion region of our Shell. From there Prism takes over by using the Unity IoC Container to create an instance of our EditorViewModel class and pass it to the EditorView constructor during the build process. Then the EditorView class takes the reference to EditorViewModel and sets it as the DataContext for the View. From there all we need to do is declare our bindings in Xaml:

EditorView.xaml

<UserControl x:Class="CodeCamp.Editor.EditorView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:cmd="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation"
    xmlns:controls="clr-namespace:CodeCamp.Common.Controls;assembly=CodeCamp.Common"
    Width="400" Height="25">
 
    <StackPanel Orientation="Horizontal">
        <StackPanel x:Name="LayoutRoot" Background="White" Orientation="Horizontal" DataContext="{Binding Path=CurrentMessage}">
            <TextBlock>Message:</TextBlock>
            <TextBox Width="200" Text="{Binding Path=Content, Mode=TwoWay}" VerticalAlignment="Top" />
            <controls:ErrorStatus PropertyName="Content" />
        </StackPanel>
        <Button Content="Send" VerticalAlignment="Top" Width="100" 
                cmd:Click.Command="{Binding SendMessage}" 
                cmd:Click.CommandParameter="{Binding Path=CurrentMessage.Content}" />
    </StackPanel>
</UserControl>

Nothing to it. You could refactor an interface from EditorViewModel. For me, sometimes I do sometimes I don’t. There isn’t a need for it, since if you’re able to keep your View clear of any logic then there isn’t anything to test. If there’s nothing to test then, in the case of the View there is no need to ever substitute a mock of EditorViewModel for the real thing. In our sample application I use interfaces because it demonstrates the principal of registering types and allowing the IoC Container to resolve those types at runtime, but unless there is a reason you need to be able to substitute concrete objects and mock objects you can keep it simple here.

ServiceLocator

With ServiceLocator you can remove the dependency on the Container. ServiceLocator is a static class with properties which expose your service interfaces. Your ServiceLocator becomes your dependency. It knows about which concrete classes map to which interfaces. When you get the value of a property ServiceLocator will return the concrete implementation:

 
public class ServiceLocator {
    public static InterfaceA { 
        get{ return new ServiceA(); }
    }
    
    public static InterfaceB {
        get{ 
            return new ServiceB(
                ServiceLocator.InterfaceA,
                ServiceLocator.InterfaceD
            );
        }
    }
    
    public static InterfaceC {
        get{
            return new ServiceC(
                ServiceLocator.InterfaceA
            );
        }
    }
 
    public static InterfaceD {
        get{
            return new ServiceC(
                ServiceLocator.InterfaceA
            );
        }
    }
}

You get the same benefits of Dependency Injection, without the dependence on the Container.

In my view Dependency Injection requires less work. With ServiceLocator you need to write the class, then you will also need to maintain a separate version of that class that returns mock objects for testing purposes. For that reason, I prefer Dependency Injection over ServiceLocator. So why bother bringing it up then?

Design-Time Databinding

ServiceLocator is great for providing sample data which can be used during design-time to allow you to be more productive. Without it you will more often than not spend a lot of time in the modify-build-run-modify cycle where every change or tweak you make requires you to run the application to see what it actually looks like. However, Blend (and now the upcoming VS 2010) has a designer which gives you a view of what your view will actually look like without running it. Blend 3 has a sample data feature which allows you to bind to a sample data source when you’re designing your view, but this requires you to maintain sample data for test scenarios as well as for the designer. Using a ServiceLocator to provide a reference to your View-Model which has been provided with mock data means you are designing your view using data that will pass through your actual View-Model. This means your design-time experience is realistic and you can have a single source of mock data that can be used for both testing and designing. \

In the sample project I am using along with this series HistoryView uses this technique.

HistoryViewModel.cs (ctor)
public HistoryViewModel(IMessageServiceAsync messageService)
{
    // store parameters as local member variables
}

MockMessageService.cs

using System;
using System.Collections.Generic;
using CodeCamp.Model;
 
namespace CodeCamp.Common.Utility
{
    public class MockMessageService : IMessageServiceAsync
    {
        #region IMessageServiceAsync Members
 
        public IAsyncResult BeginGetMessages(AsyncCallback callback, 
            object state)
        {
            return new MockAsyncResult { AsyncState = state };
        }
 
        public IList<Message> EndGetMessages(IAsyncResult result)
        {
            return new List<Message> {
                new Message { Content = "Message 1", 
                    Date = new DateTime(2009, 1, 1, 15, 02, 35) },
                new Message { Content = "Message 2", 
                    Date = new DateTime(2009, 1, 1, 15, 08, 21) },
                new Message { Content = "Message 3", 
                    Date = new DateTime(2009, 1, 1, 15, 11, 01) }
            };
        }
 
        public IAsyncResult BeginAddMessage(Message message, 
            AsyncCallback callback, object state)
        {
            return new MockAsyncResult { AsyncState = state };
        }
 
        public void EndAddMessage(IAsyncResult result)
        {
            return;
        }
 
        #endregion
    }
}

ServiceLocator.cs

using System;
using System.Diagnostics;
using CodeCamp.Common;
using CodeCamp.Common.Utility;
using CodeCamp.Common.ViewModel;
using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Unity;
using CodeCamp.Model;
using CodeCamp.Common.Services;
 
namespace CodeCamp.History
{
    public class ServiceLocator
    {
        private static IUnityContainer BuildDesignTimeContainer()
        {
            IUnityContainer container = new UnityContainer();
 
            // register view models
            container.RegisterType<IMessageServiceAsync, MockMessageService>();
 
            return container;
        }
 
        private static IUnityContainer _container;
        public static IUnityContainer Container
        {
            get
            {
                if (_container == null)
                {
                    // setup container
                    _container = BuildDesignTimeContainer();
                }
 
                return _container;
            }
            set
            {
                _container = value;
            }
        }
 
        #region ViewModels
 
        public static HistoryViewModel  HistoryViewModel
        {
            get
            {
                try
                {
                    return Container.Resolve<HistoryViewModel >();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    return null;
                }
            }
        }
 
        #endregion
    }
 
                
}

HistoryView.xaml

<UserControl x:Class="CodeCamp.History.HistoryView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:History="clr-namespace:CodeCamp.History"
    xmlns:Common="clr-namespace:CodeCamp.Common;assembly=CodeCamp.Common"
    Width="400" Height="300">
    <UserControl.Resources>
        <History:ServiceLocator x:Key="HistoryService" />
        <Common:DateFormatConverter x:Key="DateFormatter" />
    </UserControl.Resources>
    <ScrollViewer DataContext="{Binding Source={StaticResource HistoryService}, 
                                    Path=HistoryViewModel}">
        <ListBox ItemsSource="{Binding History}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock Grid.Column="0" 
                                   FontWeight="Bold" 
                                   Foreground="Green" 
                                   Text="{Binding Date, 
                                    Converter={StaticResource DateFormatter}, 
                                    ConverterParameter=H:mm:ss tt}" />
                        <TextBlock Grid.Column="1" 
                                   Text="{Binding Content}" />
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </ScrollViewer>
</UserControl>

Going backwards, notice that the ScrollViewer in HistoryView.xaml binds to the HistoryViewModel property from a static resource (defined in our UserControl) named HistoryService which is our ServiceLocator. The ServiceLocator class resolves HistoryViewModel using the Unity IoC container (I’ll explain why in a second) which injects a MockMessageService object into the HistoryViewModel object it returns to the HistoryView.

First, the reason this works is because the Xaml designer can use ServiceLocator’s static properties. The ServiceLocator class doesn’t need to be instantiated and so the designer is able to get the sample data and use it to render the view as it would be seen at runtime with live data.

DesignTimeDatabinding

Second, the reason I’m using an IoC Container when I said ServiceLocator doesn’t need it is because what this allows me to do is set the ServiceLocator.Container property at runtime from the Bootstrapper or duing IModule.Initialize. So at design-time I get a Container with mock objects from the ServiceLocator.BuildDesignTimeContainer method and at runtime I get my container with my real concrete objects and production services without having to change anything. So while ServiceLocator is a little more work, when you need design-time data it is worth the effort.

One last important thing to note with ServiceLocator, you will want to create it in the same project where your View(s) is (are) located. The reason for this is you don’t want to have to create references between different Modules because you want your Modules to be completely independent of one another. Because of this the best way to maintain this clean separation is to have a single ServiceLocator in each project where it is needed. Your mock classes can be located in your Common project and you should have everything you need without creating unnecessary dependencies between Modules.

Conclusion

We’ve covered quite a bit of ground at this point in our series. This last post should help you understand how to wire up your View to your View-Model. If you’re wondering when you’d want to use which technique, or thinking why you wouldn’t want design-time data binding (I know I asked that one when I first discovered this technique) I’ll tell you what I do. If your View requires you to build your project, run it and navigate to the view to see how it looks with a larger font size then you’ll be more productive with ServiceLocator. If you know your View will look the same in the designer as it does at runtime, then save yourself some effort and just use Dependency Injection.

Next I’ll be tackling Commands and along with Commands we’ll be looking at the best way to create a Web Service Client for your application.

Source Code

tags: , , , , , , ,

kick it on DotNetKicks.com   Shout it  

Feedback

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Nice article, again!

I don't like the idea of having to duplicate the ServiceLocator code for every single project though. Luckily DI will do the job for me.

Thanks.

Cheers,
Kevin
11/2/2009 8:37 AM | Kevin

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Kevin, I agree with you about duplication of code - it seems to me there could be a better way. I'd prefer if it didn't take so much code. However, it seems to me that it can still save a considerable amount of time when you compare the time spent to write the ServiceLocator with the time spent to rebuild and run the application so you can see how your changes look when the application runs. The ServiceLocator only need be written once and then unless you need to add new services you never have to touch the Service Locator code. 11/2/2009 1:48 PM | MarkJMiller

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Great post. It seems that discussion of ServiceLocator would benefit from discussion of the factory pattern as well. How are factory and servicelocator alike or different? 11/3/2009 6:47 AM | Jeremy Likness

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Jeremy, thanks for the feedback. But I really don't see where the benefit would be. It would seem to me that the discussion would simply muddy the waters and add confusion to users who are new to the concept of IoC. Even Fowler, when discussing IoC didn't mention factories. I chose to include DI and ServiceLocator because those are the standard patterns developers will see across any MVVM implementation. 11/4/2009 7:50 AM | MarkJMiller

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Excellent post! I always enjoy a solid technical post (and code) It saved me a good week+ - Keep up the good work! 1/4/2010 6:39 AM | Rapid Share

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I am looking at so many samples. Every one pretty much create one view == one project .Do you guys create module(Project) for each view. I feel like at the end of year we may end up with 100's project. If we are not saying each view is a module how do we define a module .Is it some thing like interrelated views together.So please...... 2/5/2010 12:14 AM | bonus de jeux

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Just to reduce the complexity. Inversion of control is simply saying that rather than the object instantiate a dependent object, that object is passed into the object. This 'inverts' the relationship. A container is separate, but when introduced handles the instantiation, creating the corresponding implementation from the injected interface.

It's not putting the dependency on the container. (unless you do something silly like use container.resolve). These classes don't reference or even know a container exists 2/8/2010 5:21 AM | Steve

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar "The result is you now have a only a single dependency – the “Container” – instead of a complex hierarchy of dependencies"

Steve, you're right. The above statement is wrong. There is no dependency on the container in the class. What I meant by the statement is that your project now has a dependency on an IoC container. However the class in question (and in the example) does not. 2/8/2010 12:32 PM | MarkJMiller

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar bonus de jeux - d'abord, arretes de mettre des liens pour casinos dans les commentaires.

As for the module/view relationship, it is a one-to-many relationship. You can have as many related views together in a single module as you like. The reason you see one-to-one in demos is because they are simplified examples. Look at the prism reference applications that come with the documentation and you'll see you can have multiple views in a module. 2/8/2010 2:23 PM | MarkJMiller

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Hi,
I am developing Application with Prism + Silverlight + WCF.
Can you send me very simple application how to use WCF with Prism in silverlight.

plz email me at
nvintt@gmail.com
nvintt@yahoo.com. 2/10/2010 12:36 PM | Vineet

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Hi Mark Nice article about MVVM Prism, I liked the Controller part it has been really confusing to me.
I am developing a Prism SL App in which i am calling WCF services(Async) from Controller and and publishing the Data(returnvalue such as cusstomer details etc) to VM and attaching this to View (by usin INotify). I think this is not right way to do, instead to use Model at client side and updating it( i am not sure).

Can u give some feed back so that help mee go in right Direction. If possible with some Sample(links, blogs or code).

Thanks
Raghav 4/5/2010 11:22 PM | Raghav

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar @Raghav - Read thru the whole series. Or if you're just interested in communicating with WCF look at parts 6 and 6b on commands. If you'd like to look at a sample, all the posts in the series point to sample source code. Download the source code and have a look. 4/6/2010 9:18 AM | MarkJMiller

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar This article presents a high level overview of Dependency Injection (DI). It aims to present the overall concept of Dependency Injection to the junior developer within the context of how it could be used in a variety of DI containers. 6/24/2010 4:09 AM | Free Online Casino Games

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar The use of a factory class is one common way to implement DI. When a component creates a private instance of another class, it internalizes the initialization logic within the component. This initialization logic is rarely reusable outside of the creating component, 6/24/2010 5:24 AM | agile informatics

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar This is a good read for me, Must admit that you are one of the best blogger I ever saw. Thanks for posting this informative post.
6/27/2010 7:44 PM | placement argent

# Its a very good post

Gravatar
Great info.I like all your post.I will keep visiting this blog very often.It is good to see you verbalise from the heart and your clarity on this important subject can be easily observed 7/2/2010 7:45 PM | injury lawyer

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Thank you for taking the time and care to listen to the community :) 7/3/2010 2:41 AM | ab circle pro reviews

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Its very easy to call the objects of the class...thanks for writing this code and sharing with programmers 7/6/2010 4:08 AM | Kids Games

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I could have used the title “Ditching Client Service Proxy” or “Avoiding Add Service Reference”, but that’s not what the meat of the post is about. However, that is fundamentally the aim of this post. The client service proxy generated when you use “Add Service Reference…” to reference your web service from your client project is used by every demo I do know. It quickly generates a proxy class for you that at first blush is “the bee’s knees”. 7/7/2010 8:39 AM | French Mortgages

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading all support relevant to Code.
7/8/2010 8:25 PM | chase personal loans

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Thanks for all the enthusiasm to offer "View-Model in Part 5" with such helpful information here. 7/8/2010 8:33 PM | chase auto loan

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar It is a strategy, I believe that your business can grow rapidly there. Many tourists spend in this way. 7/10/2010 8:01 AM | cheap seo

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I loved reading your blog. He was very well written and easy to understand. Unlike the more I read blogs that are not really good. I also found your posts very interesting. In fact after reading, I had to show my friend and he liked too! 7/11/2010 1:20 PM | hemorrhoids treatmen

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection. The latest post in a series on implementing MVVM architecture with the Prism ... 7/12/2010 11:46 AM | watch anime online

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar It is very easy to call the objects of the class ... thanks for writing this post and share
7/16/2010 3:12 AM | Toddler Shoes

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar This is a really good read for me. Must agree that you are one of the best blogger I've seen. Thanks for posting this information useful. This was just what I was looking. Return to this blog for sure! I starred this blog a while ago by the useful content and never be disappointed. Keep up the good work 7/18/2010 3:22 AM | Boys Shoes

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar His great thought to the introduction of modernization in health care. Introduction of information and technology is necessary. This will lead to the transformation of the health system. To improve the quality of health care, equity, efficiency and security through the use of this technology will lead to a significant improvement in the health of the nation. I am very proud to know that this is not happening only at random. But certain certification criteria, a set of standards, implementation specifications imposed ion adapt information and technology. 7/18/2010 4:58 AM | video games

# Opinion

Gravatar I was very pleased to find this site. I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post. 7/20/2010 6:24 PM | simulation assurance auto

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Very good post. I came across your blog and wanted to say I really enjoyed reading your blog. Either way I will subscribe to their feed, and I hope to publish soon.Online news again, I've been looking for some help.I admire what you've done here. Good to see your light on this important topic can be easily seen. Awesome post and wait for the next update 7/24/2010 12:26 PM | Auto Glass Dallas

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar To improve the quality of health care, equity, efficiency and security through the use of this technology will lead to a significant improvement in the health of the nation. 7/26/2010 8:36 AM | error fix

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I am looking for a web designer to help me out with my new restaurant website. Does anyone here have any good ideas about where to start looking? 7/27/2010 12:33 PM | scotsman ice machine

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Inversion of control code seems that it is going to help me out. 7/28/2010 4:54 AM | Freelance programmer

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Definitely agree with what you stated. Your explanation was certainly the easiest to understand clearly. 7/29/2010 1:03 AM | chase personal loans

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar The same way as we did in Java. But, it took some time for me to realize that there are other ways of doing Inversion of Control in Ruby. That’s why I never needed a DI framework. 7/31/2010 4:10 AM | flash casinos

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Really glad that yours is one of blogs that do share valued information that can help to many readers. 8/3/2010 2:51 AM | mortgage calculator with taxes

# I recently came across your article

Gravatar I recently came across your article and have been reading along. I want to express my admiration of your writing skill and ability to make readers read from the beginning to the end. I would like to read newer posts and to share my thoughts with you. 8/3/2010 9:41 PM | online casino

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar The codes you have given are great. Inversion of control is new term for me. Thank you so much. 8/3/2010 10:36 PM | Carpet Cleaning

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar A good seo consultant will help your business capitalize the ever changing needs towards online research and marketing. A good SEO expert can only be a good SEO consultant because it is an expert whose experience as well as knowledge can help your site to improve your website ranking. It is a fact that use of an expert SEO consultant can increase visibility of your site, productivity, sales as well as bottom line. 8/6/2010 4:05 AM | seo consultant london

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Casino is a great place to try one’s luck. You do not have to pay the last money. It becomes really interesting when you play online poker for fun and not to earn money. Many have got a passion to play online casino games. But before you begin to play online casino you need to have proper knowledge about online casino poker strategies. 8/6/2010 4:08 AM | best online casino

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Staffing agency can be a lead source for good number of executive jobs. And finding a company that can successfully places people with your kind of skills will be key to success. Basically what kind of position they fill or what types of openings they have can give one an idea of whether it’s worth your time to apply. 8/6/2010 4:11 AM | executive recruitment

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar The Model View ViewModel (MVVM) is an architectural pattern used in software engineering that originated from Microsoft as a specialization of the Presentation Model design pattern introduced by Martin Fowler. Largely based on the Model-view-controller pattern (MVC), MVVM is targeted at modern UI development platforms in which there is a User Experience (UX) developer who has different requirements than a more “traditional” developer (i.e. oriented toward business logic and back end development). The View-Model of MVVM is “basically a value converter on steroids” meaning that the View-Model is responsible for exposing the data objects from the Model in such a way that those objects are easily managed and consumed. 8/6/2010 4:13 AM | adwords google

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar MVVM was designed to make use of specific functions in WPF to better facilitate the separation of View layer development from the rest of the pattern by removing virtually all “code behind” from the View layer. Instead of requiring Interactive Designers to write View code, they can use the native WPF markup language XAML and create bindings to the ViewModel, which is written and maintained by application developers. This separation of roles allows Interactive Designers to focus on UX needs rather than programming or business logic, allowing for the layers of an application to be developed in multiple work streams. 8/6/2010 4:15 AM | best dating

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Travel aide will help you to find best deals on flight tickets, hotel bookings, holiday packages, best travel insurance, cheap car rental information along with affordable package holidays. 8/6/2010 4:16 AM | Cheap Hotels

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar i agreed with them. its really nice and very easy to understand clearly. thanks for sharing 8/6/2010 9:42 AM | hotfile download

#  re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Thanks for taking the time to discuss this. I've have to tell you, you are right on. Do you mind if I reference to this blog from my newsletter? 8/9/2010 1:28 AM | xbox live cards

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I recently came across your article and have been reading along. I want to express my admiration of your writing skill and ability to make readers read from the beginning to the end. I would like to read newer posts and to share my thoughts with you. 8/11/2010 2:26 AM | oroscopo 2011

# Moroccan furniture

Gravatar Have a nice day! Keep up the good job. 8/11/2010 3:29 AM | Moroccan furniture

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar The code will compile and run fine as a WPF app as well. I don't believe I have any dependencies on specific SL components. However, you will need to re-create the projects as Windows Class libraries and the Shell project as a WPF application and make sure to point the project references to the correct .NET Framwork Class libraries instead of the Silverlight (v 2.0.5.0) versions. 8/11/2010 7:28 AM | slots online

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Thanks for the post; it is educational, refreshing and right to the point. Well stated. Keep posting and I will be stopping by once in every while. 8/11/2010 8:45 PM | herbal sleep supplement

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I have come back to a few times when explaining the benefits of Dependency Injection is how the pattern relates to Service Locator. Martin Fowler thinks Service Locator is a better choice when you’re building a single application, while Dependency Injection can be more appropriate otherwise. 8/12/2010 3:38 AM | Kuber Infotek

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Grohe AG is the largest in Europe and the world's largest manufacturer of one brand and supplier of medical equipment, holding roughly eight percent of the world market. As a global brand for sanitary products and systems, GROHE is setting standards of quality, design and technology and products provide the perfect flow of water. 8/12/2010 3:49 AM | santa letters

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I have been bombarded with talk about inversion of control (IoC), dependency injection (DI) and service locators. Unfortunately, I have also heard a lot of odd comments that doesn’t really make sense. 8/12/2010 5:35 AM | limousine to los angeles

# electric adjustable beds

Gravatar
Nicely presented information in this post, I prefer to read this kind of stuff. The quality of content is fine and the conclusion is good. Thanks for the post.

8/12/2010 10:42 PM | electric adjustable beds

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar i am calling WCF services(Async) from Controller and and publishing the Data(returnvalue such as cusstomer details etc) to VM and attaching this to View (by usin INotify). I think this is not right way to do, instead to use Model at client side and updating it( i am not sure).Search Engine Optimization Services 8/13/2010 2:04 AM | Search Engine Optimization Servi

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar the mappings between your interfaces and the concrete implementations of your classes. Then when you need to get a reference 8/14/2010 12:11 AM | French Country style

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Good post! I am also going to write a blog post about this... thanks 8/15/2010 1:24 PM | Free dating sites

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar nice post keep it up thanks for sharing. 8/15/2010 10:45 PM | Cheap Chicago Tickets

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I don't believe I have any dependencies on specific SL components. However, you will need to re-create the
thongs projects as Windows Class libraries and the Shell project as a WPF application and make sure to point the project references to the correct . 8/16/2010 4:30 AM | ricky

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I recently came across your blog and have been reading along. I thought I would leave my first comment. I dont know what to say except that I have enjoyed reading Married Men Seeking Married Men and for more Married Women Seeking Married Women 8/16/2010 2:54 PM | Rishi

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I thought it would be difficult but you really made uasage of Dependency Injection in a Prism application really simple 8/16/2010 11:54 PM | online poker show

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Nice article. I will forward it to my friends and i hope they also like it.Thanks for sharing with us.... 8/17/2010 3:29 AM | Sad poems

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Th4t be an epic da shizzi4 post, th4nkie 4it & in da futures we'll be seeing more of it 8/17/2010 11:57 AM | travel

# cruises

Gravatar We7ll I8be dat9 ogr6e speekie da speekie, gratz & than4x 8/17/2010 11:57 AM | cruises

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar thatfs be43 an epci34 post 8/17/2010 11:59 AM | flight center

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar your writing skill and ability to make readers read from the beginning to the end. I would like to read newer posts and to share my thoughts with you. 8/18/2010 1:04 PM | Life Insurance Quotes

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Great webpage! I dont imagine Ive seen every one of the angles of this theme the way in which youve pointed them out. Youre a accurate star, a rock star guy. You`ve got a great deal to say and know so much about the subject that i think you ought to just teach a class about it.
8/19/2010 12:07 PM | Pariuri Sportive

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I am vb.net developer may someone convert c# code into vb.net

Thanks,
Alex 8/19/2010 2:23 PM | watch anime

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection. The latest post in a series on implementing MVVM architecture with the Prism ... 8/20/2010 2:29 AM | mattress cleaning

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar It helped me with ocean of knowledge so I really believe you will do much better in the future I appreciate everything you have added to my knowledge base.Admiring the time and effort you put into your blog and detailed information you offer! 8/20/2010 6:22 AM | online slots

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar At the web server level, WSS configures IIS to forward all requests, regardless of file and content types, to the ASP.NET session hosting the WSS web application, which either makes a certain revision of a certain file available from the database or takes other actions. Unlike regular ASP.NET applications, the .aspx which contains the WSS (and MOSS) application code, resides in SQL Server databases instead of the filesystem. ...... 8/20/2010 6:46 AM | online blackjack

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar When a component creates a private instance of another class, it internalizes the initialization logic within the component. This initialization logic is rarely reusable outside of the creating component.
seo 8/20/2010 10:00 AM | ricky

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar you will more often than not spend a lot of time in the modify-build-run-modify cycle where every change or tweak you make requires you to run the application to see what it actually looks like. 8/20/2010 11:07 AM | Freelance SEO India

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I do not understand the problem: terrorism is a war declared against the public, not just the U.S. but against the whole population in the world. Therefore, convicted terrorists to a military tribunal as war criminals. What's more fascist war criminals convicted by the Nuremberg International Tribunal, it is time for a court to try terrorists. 8/21/2010 3:12 PM | ice boxes

# My thought

Gravatar As webmaster, I am very happy to see that someone thought to post this topic. Very few people out there do not understand what all is involved in this industry, and I think we are often neglected or taken for granted. Never the less I am very happy to see that you feel the same as me, thank you very much for your blog 8/21/2010 10:03 PM | buywowaccounts

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Hey, thanks for your post. I'm not sure I have a clue what Inversion of control means, but your explanation is so clear and vivid that even a 5 year old should understand and follow it. Great job... 8/22/2010 11:20 AM | cod liver oil effects

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Inversion of control codes seems that it is going to help me out... 8/23/2010 3:06 AM | carpet cleaning herdforshire

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar This is a good post. This post give truly quality information.I’m definitely going to look into it.Really very useful tips are provided here.thank you so much.Keep up the good works.
Cool Gift
8/23/2010 1:49 PM | rishi

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar That was a great code and I have just started now to implement it. 8/25/2010 3:41 AM | Chicago mover

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar well worth the read. thank you very much for taking the time to share with those who are starting on the subject. Greetings 8/25/2010 4:05 AM | Muscle building leg exercises

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Good article and post. I really thanks to the author! 8/25/2010 4:45 AM | http://www.abcpharmacy.info

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I found so many interesting stuff in your blog especially its discussion.
8/25/2010 9:51 PM | Stun Guns

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Pretty good post.I found your website perfect for my needs. thanks for sharing the great ideas. 8/25/2010 11:11 PM | Testking 70-642

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar its really very great and informative post. thanks for sharing the information. 8/25/2010 11:56 PM | seo newcastle

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Such a very valuable information. Thanks for this excellent read. 8/26/2010 12:13 AM | Cotton Yarn

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I would like to thank you for the efforts you have made in composing this article. thanks for sharing the great information. 8/26/2010 12:18 AM | Military Boots

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Very knowledgeable reading. This is such a great resource that you are providing. 8/26/2010 1:16 AM | Motorcycle Clothing

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar This was a really quality post.Such a very good article. 8/26/2010 1:46 AM | quality inspection china

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I am happy to read a lot of useful information here in the post. Thanks for sharing it here. 8/26/2010 4:40 AM | Ramadan SMS

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar By learning these technologies, you open up so much more possibilities than
if you narrow yourself to a select few set of components.
8/27/2010 6:53 AM | Law Firm

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I enjoyed reading your nice blog. I see you offer priceless info. Stumbled into this blog by chance but I’m sure glad I clicked on that link. You definitely answered all the questions I’ve been dying to answer for some time now. Will definitely come back for more of this. Thank you so much. 8/27/2010 8:00 AM | carpet cleaner Monterey

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I will forward it to my friends and i hope they also like it.Thanks for sharing with us.... 8/27/2010 12:57 PM | Insurance

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Hello,
Thank you for the realy good posting, the site it very nice 8/27/2010 8:45 PM | Die besten Mutterwitze

# unsecured small business loan

Gravatar Really your blog have nice post so I became the permanent visitor of your blog.
Thanks for sharing this useful information. 8/28/2010 1:44 AM | robseller81

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar You guys create module(Project) for each view. I feel like at the end of year we may end up with 100's project. If we are not saying each view is a module how do we define a module .Is it some thing like interrelated views together. 8/28/2010 3:27 AM | benefits of a casino in uk

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar the best animations of the rotary engine I have ever seen. It shows the complete build of the rotary engine, and indepth animation on how the intakes open and the cycle is run. 8/28/2010 5:59 AM | bestes Internet Casino

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Hello. I wanted to drop you a note to express my gratitude. I have been following your blog for a month or so and have got a lot of good information and enjoy the way it has structured its site. I'm trying to run my own blog but I think it is too general and I want to focus more on small issues. Being all things to all people is not the only thing her paint. 8/29/2010 1:12 PM | Houston Web Design

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar social media optimization is just like search engine optimization. They are just differ in ways where they implement those things. 8/30/2010 4:17 AM | Websites reviews

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Your sharing is knowledgeable. 8/30/2010 6:19 PM | Phoenix Pool

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I thought it would be difficult but you really made uasage of Dependency Injection in a Prism application really simple.. 8/31/2010 2:39 AM | office cleaning

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I could have used the title “Ditching Client Service Proxy” or “Avoiding Add Service Reference”, but that’s not what the meat of the post is about. 8/31/2010 4:56 AM | One line messages

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Then we have to replace them with some different assumptions: small is beautiful, roots and traditions deserve preservation; variety is the spice of life, the work is only worth doing meaningful work, biodiversity is the necessary precondition for human survival. 8/31/2010 12:03 PM | jewelry buyers Houston

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Nice this kind of article, very informative.

http://www.soccerisrealfutbol.com 9/1/2010 4:23 AM | soccerfutbol

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar Good post. 9/1/2010 11:42 AM | cheap iphone

# re: MVVM with Prism 101 – Part 5b: ServiceLocator vs Dependency Injection

Gravatar I feel like at the end of year we may end up with 100's project. If we are not saying each view is a module how do we define a module .Is it some thing like interrelated views together.So please......
Thanks
9/1/2010 1:16 PM | gastric band pill

Post a comment





 

Please add 1 and 6 and type the answer here:

 

 

Copyright © Mark J. Miller