Q:

Unity in attached properties

I need to create an attached property which communicates with some service inside it's PropertyChanged event handler. E. g.
private static void IsRegisteredPropertyChanged(DependencyObject target,
                                            DependencyPropertyChangedEventArgs e)
{
    //how to resolve this without service locator?
    IService someService = ServiceLocator.Resolve<IService>();

    if ((bool)e.NewValue)
    {
        someService.Register(target);
    }
    else
    {
        someService.Unregister(target);
    }
}

As I understand, the event handler will always be static. Is there any way to inject a dependency for this event handler using Unity except with Service Locator pattern? If not then maybe there are any alternatives that let you declaratively register view elements to that service?

A:

The only way to do proper DI when the static keyword is involved is through Method Injection.
If you can inject a service through one of the method parameters, you can do it - otherwise you can't.
You can still use a Service Locator, but that's not DI...

