Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
981 B
9
Indexable
Never
var dispatcher = Dispatcher.CurrentDispatcher;
var subiektDispatcher = new SubiektDispatcher(subiekt, dispatcher);

    class SubiektDispatcher
    {
        Subiekt subiekt;
        Dispatcher dispatcher;

        public SubiektDispatcher(Subiekt subiekt, Dispatcher dispatcher)
        {
            this.subiekt = subiekt;
            this.dispatcher = dispatcher;
        }

        public void Invoke(Action<Subiekt> action)
        {
            dispatcher.Invoke(() =>
            {
                action(subiekt);
            });
        }
    }

// uzycie:
subiektDispatcher.Invoke(subiekt =>
{
  var documentsCollection = subiekt.SuDokumentyManager.OtworzKolekcje();
});

// spinka z kontenerem DI (AutoFac):
            builder.Register(ctx => dispatcher)
                .As<Dispatcher>()
                .ExternallyOwned();

            builder.Register(ctx => subiektDispatcher)
                .As<SubiektDispatcher>()
                .InstancePerLifetimeScope();