TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Akhil Mittal
NA
26.3k
7.8m
How can I resolve dependency of a dependency in Web API usin
Oct 15 2014 8:47 AM
I have a web API controller, and I am using Unity.WebAPI for resolving dependency.
Following is my Bootstrapper.cs code,
public static class Bootstrapper
{
/// <summary>
/// Public method to initialise UnityContainer.
/// </summary>
public static void Initialise()
{
var container = BuildUnityContainer();
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
// register dependency resolver for WebAPI RC
GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);
}
/// <summary>
/// Register built in types.
/// </summary>
/// <returns></returns>
private static IUnityContainer BuildUnityContainer()
{
var container = new UnityContainer();
container.RegisterType<IUserService, UserService>().RegisterType<UnitOfWork>(new HierarchicalLifetimeManager());
return container;
}
}
This resolves my UserService to my UsersController , my controller code is,
private readonly IUserService _userService;
/// <summary>
/// Public constructor to initialize user service instance
/// </summary>
/// <param name="userService"></param>
/// <param name="tokenService"> </param>
public UsersController(IUserService userService)
{
_userService = userService;
}
Now suppose My UserService also depends on any other class say Employee and needs a new Employee() instance wheneven UserService instance is needed.
How can I resolve the dependency of this new Employee() class in my UserService.
Also note that Employee class does not Implement any Interface.
Please answer.Or let me know if any further clarification is needed.I hope I am clear in asking the question.
Reply
Answers (
0
)
Token based authentication in Web API 1.1
Regarding API Integration