Skip to content
This repository has been archived by the owner on May 21, 2022. It is now read-only.
Lazy Byte edited this page Nov 24, 2018 · 17 revisions

OWIN Web API Starter Template

This is a Visual Studio template that provides main functionality that I think many of us implement while creating new Web API using OWIN.


If you would like starter template for ASPNET.CORE please look into this.


Included functionalities:

  • CORS
  • Web API exception handling
  • Web API exception logging.
  • Autofac
  • Formatters
  • Routes

VS Gallery Link

VSIX installer can be downloaded here

CORS

Allowed origins can be set in Web.config by default template will set it to: "*", but you should change it to list of concrete origins:

`<add key="cors" value="http://mysite.com;http://mysite2.com" />`

Formatters

Default formatter is JSON with camel case (XML formatter has been removed). You can edit formatter configuration in FormatterConfig.

In case you are going to work with files this might come in handy: https://github.com/iLexDev/ASP.NET-WebApi-MultipartDataMediaFormatter because Web API doesn't have a built in support for this like Asp.MVC does through HttpPostedFileBase.

Routes

Usage of route attributes has been enabled.

You cane also find some basic routing examples in TestController

Exception Logging and Handling

Web API provides means to log and handle its exception through: IExceptionLogger and IExceptionHandler interfaces.

You can find their implementations under: ApiExceptionLogger and ApiExceptionHandler.

Note: You will need to provide logging provider in ApiExceptionLoggeror nothing will be logged. I didn't want to implement a concrete one since they are easy to implement and everyone has their own favorite.

Autofac

I used Autofac because I like it the most, and most of DI providers have similar usage so it won't be a big issue to replace it with one that you like better, and for people who are new to DI containers it might be a great help.

Upon installation of template you will have Autofac wired with Web API. Regarding component registration API controllers will be registered, but all other types will need to be added under AutofacConfig

Visual Studio Version Support

Template currently works on: VS 2017 (Community and above).