Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How i can intergate with Prism Unity? #20

Closed
ghost opened this issue Aug 17, 2018 · 2 comments
Closed

How i can intergate with Prism Unity? #20

ghost opened this issue Aug 17, 2018 · 2 comments

Comments

@ghost
Copy link

ghost commented Aug 17, 2018

i found Jot.Unity but how use it?

@lorinkundert
Copy link

lorinkundert commented Jun 18, 2019

I use ReactiveUI so it is more complicated but the concepts are the same, in your Program.cs or a BootStrapper class, I use

Locator.CurrentMutable.RegisterConstant(PersistanceService.Tracker, typeof(Tracker));

PersistanceService is the class you can find in the samples and documentation, it may have a different name, the next step is to use the service like so,

"Locator.Current.GetService().Track(this);"

@anakic
Copy link
Owner

anakic commented Feb 28, 2022

So this is an old issue that I never got around to answering. It's a few years too late now, especially since it seems Unity is no longer maintained, but I'm closing old issues so here's the answer...

I use the following extension to apply tracking to all resolved objects:

public class TrackingExtension : UnityContainerExtension
{
    class TrackingStrategy : BuilderStrategy
    {
        readonly Tracker tracker;
        public TrackingStrategy(IUnityContainer container)
        {
            tracker = container.Resolve<Tracker>();
        }

        public override void PostBuildUp(ref BuilderContext context)
        {
            base.PostBuildUp(ref context);
            if (RemotingServices.IsTransparentProxy(context.Existing) == false)
            {
                Type targetType = context.Existing.GetType();
                tracker.Track(context.Existing);
            }
        }
    }

    protected override void Initialize()
    {
        Context.Strategies.Add(new TrackingStrategy(Container), UnityBuildStage.Creation);
    }
}

I register it with the container like so: container.AddExtension(new TrackingExtension());.

Sorry about the extremely late reply.

@anakic anakic closed this as completed Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants