I have a base web API project which does the main operations and I have custom/bespoke web API project. The custom project does extra functions(bespoke) additional to the existing functions done by the base API.
How do I basically convert an API project to a plugin and access it from base API mainly at the controller level?
What I have tried:
I have tried to develop a sample project to experiment the proof of concept.
Here I have a base API project and custom API project in same solution.
In the base API: I have connected a simple Database to it through EF and created an interface with a add method to insert data to a table. I have implemented it a controller.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PluginTestProject.Interfaces
{
interface IEmployee
{
bool AddEmployee();
}
}
I have a controller which implements this interface:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace CustomeAPI.Controllers
{
public class CustomEmployeeController : IEmployee
{
public bool AddEmployee()
{
try
{
var employee = new tblEmployee();
employee.firstName = "John";
employee.lastName = "Snow";
employee.address = "address test";
using (var context = new PluginTestDBEntities())
{
context.tblEmployee.Add(employee);
context.SaveChanges();
return true;
}
}
catch (Exception e)
{
return false;
}
}
}
}
This all works fine. But what I need is below:
In the Custom API:
1. I need to convert it to a plugin and access it from the base project.
I should be able to tell which controller (base controller or custom controller) to look up.
Firstly, is it possible and if so please help me how to achieve it?
Please help as I am new to web API and plugins.
Thanks in advance!