Getting Started With MVCRpxLib is designed to easily intergrate into an ASP.Net MVC application. Particularly if you are already using a IOC container to handle the instantiation of your controllers. Using dependency injection1. Setup your settingsFirst create an implementation of IRPXApiSettings. This can simply delegate to the provided RPXApiSettings class through its constructor or you can create your own implementation. public class MyRPXApiSettings : RPXApiSettings {
public MyRPXApiSettings() : base("myApiBaseUrl", "myApiKey") {}
}or public class MyRPXApiSettings : IRPXApiSettings {
public string ApiKey { get { return "myApiKey"; } }
public string ApiBaseUrl { get { return "myApiBaseUrl"; } }
public IWebProxy WebProxy { get { return null; /* or your proxy object */ } }
}2. Register with the containerRegister the settings class (which is a dependency for the service) and the service itself with your container. For example using Autofac... builder.Register<MyRPXApiSettings>().As<IRPXApiSettings>();
builder.Register<RPXService>().As<IRPXService>(); 3. Inject the service as a dependency to your controllerSet up the service as a dependency for your controller and then let the container work its magic. public class AuthenticationController : ControllerBase {
private IRPXService rpxService;
public AuthenticationController(IRPXService rpxService) {
this.rpxService = rpxService;
}
}Without dependency injection1. Manually create the dependency in the controllerIn the constructor of the controller you can manually construct your service dependency by doing the following... public class AuthenticationController : ControllerBase {
private IRPXService rpxService;
public AuthenticationController() {
var settings = new RPXApiSettings("myApiBaseUrl", "myApiKey");
this.rpxService = new RPXService(settings);
}
}
|