I have looked at several tutorials for setting up Unity Container for Web API 2 for the purpose of implementing Dependency Injection but they all used older versions of Unity so they don't help my situation. The version of Unity I am using is Unity.Asp.Net.WebApi 5.0.11.
It only created two files in the APP_Start folder for me when I install it as far as I can see which are shown below:
UnityConfig.cs UnityWebApiActivator.cs
I have registered my Types in the Application_Start() method but I still get errors when I run my code. The following are my Global.asax and UnityConfig files.
protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); }
public static void RegisterTypes(IUnityContainer container) { container.RegisterType<IPayment, VisaPayment>(); container.RegisterType<IPayment, MasterPayment>(); }
I tried to add the following code to the Global.asax file but Visual Studio throws errors which basically said that they are objects which do not exist.
AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); BundleTable.Bundles.RegisterTemplateBundles(); Bootstrapper.Initialise();
Can someone please help point me to a web page that explains what I need to do to configure Unity for WebAPI 2, thanks.