I'm currently setting up a new MVVM WPF project and I would like to use autofac for my viewmodels injection and I think I could create a Postsharp custom attribute to automatically resolve dependencies when this custom attribute is used, like in this example here : autofac postsharp
Or, Maybe there is a way to accomplish the same just with Postsharp without Autofac ?
this example doesn't work on MVVM WPF because there is no Dependency Resolver like this example (MVC)
so, for now, I just have a fresh bootstrapper :
public class BootStrapper
{
public IContainer BootStrap()
{
var builder = new ContainerBuilder();
var container = builder.Build();
return builder.Build();
}
}
and the mvc custom postsharp attribute example :
[Serializable]
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class AutofacResolveAttribute : LocationInterceptionAspect
{
public override void OnGetValue(LocationInterceptionArgs args)
{
args.ProceedGetValue();
if (!args.Location.LocationType.IsInterface) return;
if ( args.Value != null )
{
args.Value = DependencyResolver.Current.GetService(args.Location.LocationType);
args.ProceedSetValue();
}
}
}
there are some postsharp examples (without autofac) here (that I don't really now how to adapt for my requirements): postsharp global composition container
Does someone know how to achieve this ?