Owin1. OWIN
Open Web Interface for .NET (owin.org)
Luboš Karásek | 19. 2. 2012
GMC Software Technology AG
2. Content
• Why OWIN
• App function
• Middleware, IAppBuilder
• Startup
• Examples
• Discussion
2
5. Web has changed
• Mobile clients, HTML5, Cloud
• Distributed applications – no IIS, Linux
• ASP.NET is not always suitable
• New .NET community servers and frameworks
needs common interface
5
7. Introduction of terms
Func<T, TResult>
string Convert(int i) { return i.ToString(); }
Func<int,string> convertDelegate = Convert;
string s = convertDelegate(1); //same as Convert(1)
Task
Represents an asynchronous operation
• IsCompleted (Task<TResult> property Result)
• IsFaulted (property Exception)
• Wait
7
10. Middleware
using AppFunc = Func<IDictionary<string, object>, Task>;
Func<AppFunc, AppFunc> middleware = AddTime;
static AppFunc AddTime(AppFunc next)
{
return env =>
{
env ["started"] = DateTime.UtcNow;
return next(env);
};
}
https://github.com/owin/gate/blob/master/src/Main/Gate.Middleware/Static.cs
10
11. Application Startup
NuGet package Owin
namespace Owin
{
public interface IAppBuilder
{
IDictionary<string, object> Properties { get; }
IAppBuilder Use(object middleware, params object[] args);
object Build(Type returnType);
IAppBuilder New();
}
}
https://github.com/owin/owin/blob/master/src/Owin/IAppBuilder.cs
11
13. Links
• http://owin.org/
• http://nancyfx.org/
• https://github.com/davidfowl/OwinHttpClient
• http://nuget.org/packages?q=owin
• http://www.sinatrarb.com/
• http://www.strathweb.com/2012/12/running-aspnet-web-api-with-
owin-and-katana
• http://www.sparkjava.com/
13