Category Archives: c#

August, 2014

ASP.NET Web API 2: Recipes is out!

ASP.NET Web API 2 Recipes My long promised book, ASP.NET Web API 2: Recipes has been published by Apress last week. I announced the book a while ago, when I also tried to explain the general idea behind the book. I nshort, I really wanted to write a no-nonsense, blog-like, problem-solution book for Web API.

Since then, as you may have noticed, the title got changed to reflect the latest iteration of Web API. The majority of recipes are compatible with both v1 and v2 of the framework, however some recipes are obviously Web API 2 only (i.e. attribute routing related), and there are actually a couple of ones in there that only work with ASP.NET Web API 2.2 – so it’s all up-to-date!

It’s been a tremendous journey 9 month journey (the work started in the winter) and there are so many people – the Apress crew, my friends, family, and most importantly, the wonderful ASP.NET community and the readers of this blog, that made it all happen. Thank you – I owe you guys big time!

You can get the book at:

Amazon
Barnes and Noble
Apress

The source code is at Github (I will blog about it separately). And please don’t be too harsh :)

July, 2014

Dependency injection directly into actions in ASP.NET Web API

There is a ton of great material on the Internet about dependency injection in ASP.NET Web API. One thing that I have not seen anywhere though, is any information about how to inject dependencies into the action, instead of a controller (constructor injection).

Injecting your dependencies directly into an action, rather than in the controller is a very reasonable approach, as it helps you falling into an over-injecting trap, and perhaps resolving too much things, for no real reason.

With Web API, it’s actually extremely easy to do, so let’s go ahead and implement it.

More after the jump.

Continue reading

Building a strongly typed route provider for ASP.NET Web API

ASP.NET Web API 2.2 was released last week, and one of the key new features is the ability to extend and plug in your own custom logic into the attribute routing engine.

Commonly known as “attribute routing”, it’s actually officially called “direct routing”, because, as we are about to show here, it’s not necessary to use it with attributes at all, and you can plug in any route provider into it.

More after the jump.

Continue reading

June, 2014

May, 2014

Announcing ASP.NET Web API Recipes

81iUYKuTehL._SL1500_It is my pleasure to announce that this summer my ASP.NET Web API book will be released. It’s entitled "ASP.NET Web API Recipes", and will be published by Apress.

While the publication date is not set in stone yet (probably early August), you can already pre-order at:
Apress
Amazon

The idea behind the book is quite simple – to discuss and dissect some of the most common problems and issues you might encounter in your work with Web API solutions.

There is going to be a total of 12 chapters with about 10 recipes per chapter (the number varies obviously). You will also get a full VS project with source code per each recipe.

Continue reading

April, 2014

Ignoring routes in ASP.NET Web API

If you use centralized routing, it is occasionally needed to ignore a greedy Web API route so that the request can be processed by some other component or handler.

One of the tiny overlooked features of Web API 2.1 was that it finally shipped with a cross-host way to ignore routes. It’s not too exciting, as it’s something that’s been in MVC for ages, but it’s nice to finally have an easy way to do it in Web API.

Continue reading

Opt in and opt out from ASP.NET Web API Help Page

The autogenerated ASP.NET Web API help page is an extremely useful tool for documenting your Web API. It can not only present information about the routes, but also show sample requests and responses in all of supported media type formats, and even display information for DataAnnotations.

However, more often than not, you don’t want all endpoints to be visible in the help page. Let’s have a look at how you can opt in and opt out from the ASP.NET Web API Help Page with your resources.

Continue reading

March, 2014

ASP.NET Web API exception logging with Raygun.io

Jon Galloway recently wrote a monster 4-part series covering the new features of MVC 5.1 and Web API 2.1 releases. One thing he mentioned was the new IExceptionLogger for Web API, and he called out the community to provide some example implementations of it.

Therefore, let’s have a look at how you’d approach that – with a sample of logging Exceptions to the excellent Raygun service from Mindscape.

Continue reading

Per request tracing in ASP.NET Web API

Web API allows you to plug in extensive logging mechanism through the ITraceWriter service. This will log all important events in the pipeline – such as selection of the controller, action, parameter binding and so on – all of which are extremely important in debugging all kinds of issues.

However, any existing instance of an ITraceWriter would log all of the information aside – into a log file, trace, database. But what if you wanted all the trace information produced while the given request was being processed, to be returned together with the server response?

Let’s have a look.

Continue reading

February, 2014

Running the OWIN pipeline in the new .NET Azure Mobile Services

OWIN in ZUMO!

Yesterday, a preview of the .NET Azure Mobile Services has been released. Despite the fact that I’d rather see a scripted C# support :) – I am still very excited about this new .NET support, as ZUMO is one of my favorite Azure offerings.

The whole thing is in preview right now and runs on Web API (version 5.1 at the moment, so not the latest) but the team has made several very smart decisions, which I am sure the community will welcome with open arms. One of them is the ability to plug in your OWIN pipeline!

Continue reading