0

I'm a new customer of NDpend, so please excuse me my question is stupid...I wish to have a rule that shows me when I've got a constructor has a particular line of code. Consider that example

public StatusViewModel
{
   this.userService = ServiceLocator.Default.ResolveType<IUserService>();
}

Is it possible? considering that I have it to be defined in the Constructor and need to have a reference to ServiceLocator.Default.ResolveType

Thanks

advapi
  • 3,661
  • 4
  • 38
  • 73

1 Answers1

1

If you want to enforce that the constructor is accessing

ServiceLocator.Default.ResolveType<IUserService>()

The rule should look like

warnif count > 0
from m in Application.Methods
where m.IsConstructor 
&& !m.IsUsing("Microsoft.Practices.ServiceLocation.ServiceLocator.get_Default()") 
&& !m.IsUsing("Microsoft.Practices.ServiceLocation.ServiceLocator.ResolveType<T>()")
select m
Patrick from NDepend team
  • 13,237
  • 6
  • 61
  • 92