Retrieving repositories from a Unit of Work

Topics: Questions
Sep 11, 2014 at 12:08 PM
I'm using the example in the documentation and combine it with a Entity Framework.

I have an UoW created but then I get lost in the documentation:
"Once a UoW is created, it can be used to resolve repositories. To retrieve a repository from the UoW, the following conditions must be met:
  • The container must be registered in the ServiceLocator as Transient type. If the repository is declared as non-transient, it will be instantiated as new instance anyway.
    Where do I register this, I think in app.xaml.cs?
    I think it will look something like this
    var serviceLocator = ServiceLocator.Default;
But what do I register, UnitOfWork?

Please help me with this step forward

Kind regards

Sep 11, 2014 at 3:25 PM
You need to register the repositories.
Sep 15, 2014 at 8:23 AM

this helps me a little bit.

So I have to add code to OnStartUp in app.xaml.cs, but I'm struggling what code.

Can you provide an example how I register an entity?

Kind regards

Sep 15, 2014 at 8:25 AM
Something like this:
var serviceLocator = ServiceLocator.Default;

serviceLocator.RegisterType<IMyRepository, MyRepository>(RegistrationMode.Transient);
Sep 15, 2014 at 9:08 AM

That gave me a step forward.

The last line actually has to be
serviceLocator.RegisterType<IRepository, Repository>(RegistrationType.Transient);

I work further on this, on to the next quetsions ....

Kidn regard