Passing Func<T> to controller constructure when using Unity IoC with MVC, advantages?
- by user1361315
I was looking at a sample of how to setup Unity IoC with MVC, and noticed someone who recommended the approach of having the parameters of Func. I believe the advantage is this is kind of like lazy loading the service, if it never gets called it will never get executed and not consume any resources.
private readonly Func<IUserService> _userService;
public CourseController(Func<IUserService> userService)
{
this._userService = userService;
}
Versus a parameter without a Func:
private readonly IUserService _userService;
public CourseController(IUserService userService)
{
this._userService = userService;
}
Can someone explain to me the differences, is it really more effecient?