Creating a Service API

I have created a set of videos that demonstrate how to create a Service API. This service API is in the context of an application that provides a specific API for other parts of the application to use. It is not an externally facing API that is used. However, if you front this service API with some externally exposed end-points (i.e., Web Services, ASP.NET Web API), you can expose specific end-points of the service. In our example, we have a single service API. However, a typical enterprise application would have several services. Therefore, services could be using other services through their exposed API – then you would want to see the video on dependency injection below to see how to inject other services into a specified target service.

Service API Overview – Part I

The following video demonstrates how to create a simple service API for an application. Basically, you are starting with .NET/C# project and adding an interface and another class that implements that interface. The interface is the key. It defines what is accessible from the API as you will see.

Service API Code – Part 2

This video shows how the service is setup in the project using interfaces and concrete classes that implement the interfaces. As mentioned, an  entity-driven approach was used in this application. Therefore, you will see a set of interface partial files that make up the actual interface. There is also a set of xService.EntityName.cs files that make up the implementation of the interfaces. The motivation for this convention was to support the code generation using entities as the domain source.

 

Service API Dependency Injection – Part 3

There is no way around it. Most services will some dependencies on other services or types. Use dependency injection when possible to supply the service with what it needs to do its job. The following video demonstrates how Autofac is used to inject types into the constructor of the specified service.