Skip to main content

Posts

Showing posts from 2017

How to implement Dependency Injection Using Ninject

When i was a little young at programming, i have always wondered, why the need for dependency injection, why the need for creating more work for yourself by creating objects and injecting it to the constructor of the dependent object, where you can instantiate the object directly from your codebase, not until i realised the importance, i’m sure some cool developer are asking some of this questions that i once asked, in this article i intend to answer some of this question and also show some quick implementation of dependency injection with Ninject. According to Wikipedia, the intent behind dependency injection is to decouple objects to the extent that no client code has to be changed simply because an object it depends on needs to be changed to a different one. The main aim here is to adopt a modular design approach, where there are lots of small blocks loosely coupled with each block knows very little about its neighbour other than how it connects to them, this approach greatly helps …

How to implement RESTful API Versioning in ASP.NET Web API 2 using IHttpRouteConstraint

The only thing constant in life is change, and that is proved everyday in our industry, API’s are cool to extend the functionality of your application and expose it to other developers. The cool thing about IT and software, it’s that things changes quite rapidly and so it’s the technology, hence technology can change and the needs of your organisation can change, hence in order to keep serving this evolving needs and keep been relevant, your api might need to change also. Small changes can be accommodated within the initial version, but changes that will risked breaking the existing code, will required the need for versioning.

Implementing a custom IHttpRouteConstraint

According to msdn, a IHttpRouteConstraint simply Represents a base class route constraint. What then is a route constraint? A route constraint simply gets or sets a dictionary of expressions that specify valid values for a URL parameter.

publicclassApiVersionRouteConstraint : IHttpRouteConstraint
  {

publicApiVersionRouteCo…