0
votes

i try to use DI in mvvm light like my post

can some one give me simple sample to use

depedency injection to inject service in view model mvvm?

can some one help me?

1

1 Answers

0
votes

It is based on IoC container you using. If you are using PRISM, you need to register the service contract and concrete type in bootstrapper.

    protected override void ConfigureContainer()
    {
        this.container.RegisterType<IMyService, MyService>();
    }

The registered contracts will be injected through constructor in your viewmodel.

    public MyViewModel(IMyService myService)
    {
    }

The life time of dependencies can also be controlled using LifeTime Managers. More information on that,

http://msdn.microsoft.com/en-us/library/ff647854.aspx