Q:

How can I set up the container for a wpf application to share dependencies per graph

I have a fairly well structured and large wpf mvvm application which uses castle windsor as a container. 
My root has a mix of actions with typed factories and repositories.
I would like all my actions to have shared dependencies per graph.
If all my actions only used typed factories which crated view models this would be easy with registering the repositories with BoundTo < ViewModelBase > ()...
My current solution uses
BoundTo< Object >() which has it's downsides, for example, all the root actions share repositories.
I have searched for solutions but not found any.
I would prefer to use castle windsor as my container.
Can anyone help me with this?

A:

What I did is use BoundTo. Just have any class that you want to have it's own graph implement ISomeMarkerInterface, which is just an empty interface class. If I'm not mistaken, you need to register ISomeMarkerInterface as an additional interface for the class.
Good luck,
Marwijn.
== EDIT ==
If you really need that flexibility try using a CustomRootSelector :
using System.Diagnostics;
using System.Linq;
using Castle.MicroKernel;
using Castle.MicroKernel.Registration;
using Castle.Windsor;

namespace ConsoleApplication3
{
    public class Root1
    {
        public Dep1 D1 { get; set; }
        public Dep1 D2 { get; set; }
        public Dep2 D3 { get; set; }
        public Dep2 D4 { get; set; }
    }

    public class Root2
    {
        public Dep1 D1 { get; set; }
        public Dep1 D2 { get; set; }
        public Dep2 D3 { get; set; }
        public Dep2 D4 { get; set; }
    }

    public class Dep1
    { 
    }

    public class Dep2
    { 
    }

    public class CustomScopeRootSelector
    {
        private readonly object[] _roots;

        public CustomScopeRootSelector(params object[] roots)
        {
            _roots = roots;
        }

        public IHandler Selector(IHandler[] resolutionStack)
        {
            return resolutionStack.FirstOrDefault(h => _roots.Contains(h.ComponentModel.Implementation));
        }
    }

    class Program
    {
        static void Main()
        {
            var container = new WindsorContainer();
            var rootSelector = new CustomScopeRootSelector(typeof (Root1), typeof (Root2));
            container.Register(
               Component.For<Root1>().LifestyleTransient(),
               Component.For<Root2>().LifestyleTransient(),
               Component.For<Dep1>().LifestyleBoundTo(rootSelector.Selector),
               Component.For<Dep2>().LifestyleBoundTo(rootSelector.Selector)
               );
            var r1 = container.Resolve<Root1>();
            var r2 = container.Resolve<Root2>();

            Debug.Assert(r1.D1 == r1.D2);
            Debug.Assert(r1.D1 != r2.D1);
        }
    }
}

I Hope the code explains enough. If you have questions let me know.

