Click here to Skip to main content
15,908,013 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: WPF Dialog Service via Binding Pin
Adrian Alexander30-Jan-12 9:22
Adrian Alexander30-Jan-12 9:22 
GeneralRe: WPF Dialog Service via Binding Pin
SledgeHammer0130-Jan-12 10:43
SledgeHammer0130-Jan-12 10:43 
GeneralRe: WPF Dialog Service via Binding Pin
Adrian Alexander30-Jan-12 14:28
Adrian Alexander30-Jan-12 14:28 
AnswerRe: WPF Dialog Service via Binding Pin
SledgeHammer0130-Jan-12 14:54
SledgeHammer0130-Jan-12 14:54 
GeneralRe: WPF Dialog Service via Binding Pin
Pete O'Hanlon30-Jan-12 23:06
mvePete O'Hanlon30-Jan-12 23:06 
GeneralRe: WPF Dialog Service via Binding Pin
Adrian Alexander6-Feb-12 19:45
Adrian Alexander6-Feb-12 19:45 
GeneralRe: WPF Dialog Service via Binding Pin
Mycroft Holmes30-Jan-12 13:20
professionalMycroft Holmes30-Jan-12 13:20 
GeneralRe: WPF Dialog Service via Binding Pin
SledgeHammer0130-Jan-12 13:32
SledgeHammer0130-Jan-12 13:32 
Honestly, when I was trying to figure out DI, I was never able to find any good articles, thats why it was so hard to wrap my head around. All the samples were very complicated Smile | :) . The way you write the code depends on what DI container you use (there are about 10+ open source ones -- I use my own light weight one).

Basically, using the ServiceLocator pattern, you'd write code like:

C#
class MyClass : ViewModelBase
{
   private IDialogService _dlgService = null;

   public MyClass()
   {
      _dlgService = ViewModelBase.ServiceLocator.GetService<IDialogService>();
   }
}


DI (Dependency Injection) does it automatically for you:

C#
class MyClass : ViewModelBase
{
   private IDialogService _dlgService = null;

   public MyClass(IDialogService dlgService)
   {
      _dlgService = dlgService;
   }
}


The benefit of DI is that depending on your MVVM framework, everything is automatic. In my MVVM framework, I have the DI integrated with the ViewLocatorService, so when the view is created, it uses the ViewLocator to automatically create the ViewModel. It automatically passes in all the dependent objects into your VM constructor.

Basically instead of new'ing up MyClass, you do something like:

MyClass m = ViewModelBase.DIContainer.Resolve<myclass>();

doesn't seem like much of a benefit when you are only taking in one service Smile | :) , but in a complex system, you could be taking in 10 services, and they could have dependencies of there own, etc.

Basically, DI handles passing in any registered objects into constructors and creating all necessary objects for you.

It also makes it easy to see what services a class is dependent on by looking at the constructor. A lot of the DI engines also allow you to not use the constructor method, but inject properties.

Like I said, I use my own light weight DI engine, but I think the most popular "main stream" ones are Unity and AutoFaq.
AnswerRe: WPF Dialog Service via Binding Pin
Pete O'Hanlon30-Jan-12 5:48
mvePete O'Hanlon30-Jan-12 5:48 
GeneralRe: WPF Dialog Service via Binding Pin
Adrian Alexander30-Jan-12 5:49
Adrian Alexander30-Jan-12 5:49 
Questionerror SocketError.AccessDenied on silverlight Pin
ptcnbaoduong29-Jan-12 15:17
ptcnbaoduong29-Jan-12 15:17 
AnswerRe: error SocketError.AccessDenied on silverlight Pin
Mycroft Holmes29-Jan-12 16:40
professionalMycroft Holmes29-Jan-12 16:40 
AnswerRe: error SocketError.AccessDenied on silverlight Pin
Dean Oliver29-Jan-12 18:34
Dean Oliver29-Jan-12 18:34 
AnswerRe: error SocketError.AccessDenied on silverlight Pin
Abhinav S29-Jan-12 18:54
Abhinav S29-Jan-12 18:54 
Questionsilverlight Pin
ptcnbaoduong29-Jan-12 15:16
ptcnbaoduong29-Jan-12 15:16 
AnswerRe: silverlight Pin
Dean Oliver29-Jan-12 18:30
Dean Oliver29-Jan-12 18:30 
QuestionBasic Silverlight Solution Structure Pin
Kevin Marois29-Jan-12 9:51
professionalKevin Marois29-Jan-12 9:51 
AnswerRe: Basic Silverlight Solution Structure Pin
Mycroft Holmes29-Jan-12 13:42
professionalMycroft Holmes29-Jan-12 13:42 
AnswerRe: Basic Silverlight Solution Structure Pin
Abhinav S29-Jan-12 19:00
Abhinav S29-Jan-12 19:00 
Questionbinding one listview to two observablecollections Pin
Vincent Beek28-Jan-12 23:08
Vincent Beek28-Jan-12 23:08 
AnswerRe: binding one listview to two observablecollections Pin
Pete O'Hanlon29-Jan-12 2:14
mvePete O'Hanlon29-Jan-12 2:14 
AnswerRe: binding one listview to two observablecollections Pin
Abhinav S29-Jan-12 19:03
Abhinav S29-Jan-12 19:03 
QuestionLoad/Save WPF application settings Pin
Praveen Raghuvanshi27-Jan-12 7:32
professionalPraveen Raghuvanshi27-Jan-12 7:32 
AnswerRe: Load/Save WPF application settings Pin
SledgeHammer0127-Jan-12 9:31
SledgeHammer0127-Jan-12 9:31 
GeneralRe: Load/Save WPF application settings Pin
Praveen Raghuvanshi30-Jan-12 6:26
professionalPraveen Raghuvanshi30-Jan-12 6:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.