Reputation: 41
I'm trying to use WCF REST Services and Unity (Enterprise Library 5), but can not find examples of how to implement the resolution of the services using Unity. I would like to call the registration of all interfaces and implementations for resolution in global.asax.
I'm using the following class to register the container:
public class DependencyResolver
{
public static IUnityContainer Container { get; private set; }\
static DependencyResolver()
{
Container = new UnityContainer()
.AddNewExtension<EnterpriseLibraryCoreExtension>()
.RegisterType<IServiceDAO, ServiceDAO>()
.RegisterType<IServiceBO, ServiceBO>()
.RegisterType<IService, Service>();
}
}
I searched but could not find enough examples, someone would have a code example with this solution applied?
I found some examples, like How do I pass values to the constructor on my wcf service? but I want the same context for all services. I want something like this http://entlibex.codeplex.com/wikipage?title=Unity%20Service%20Behavior&referringTitle=Documentation but in my case I don't have a svc file.
Thank you.
Upvotes: 2
Views: 1540
Reputation: 8101
Why are you using WCF 4 REST? WCF 4 REST is a little bit out dated and hard to use.
I suggest you to use ASP.NET Web API (former WCF Web API). It's easier to use for REST service and with DI/IoC containers (in WCF you should write your own host, behavior etc.) as it has good built-in connectivity support for DI/IoC.
Here is example:
http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver
Upvotes: 3