Вопрос

I'm using caliburn.micro and I've configured Bootstrapper as shown here: bootstrapper configuration, but unfortunatelly I can't find a way to request exported value as a new instance - container always returns singleton.

I've been working also with PhoneContainer (WindowsPhone) and it has great features as PerRequest and Singleton. Is there something like that for WPF?

Это было полезно?

Решение

If you are using MEF as in the article then when ever you want an instance to be created Per Request export it like this:

interface IFileReader {
    int ReadChar(string fileName);
}

[Export(typeof(IFileReader))]
[PartCreationPolicy(CreationPolicy.NonShared)]
class FileReaderImpl : IFileReader {
    // IMPLEMENTATION GOES HERE
}

Of course this is specific to MEF (MEF Lifestyles), but if you want you can use your favorite container, there is one provided with Caliburn.Micro called SimpleContainer, the docs for that will be out soon but the API is pretty intuitive and if you like you can use other containers like Unity, Ninject, etc. Check out this link about using Unity, the process for other containers is pretty similar.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top