title: Asp.Net Core 2.x middleware syntax
body: <p>I encountered several ways of writing simple middleware directly in Startup.Configure() method:</p>
  
  <pre><code>// Syntax 1.
  app.Use((context, next) =&gt;
  {
      context.Response.Headers.Add("X-Content-Type-Options", "nosniff");
      return next();
  });
  
  // Syntax 2.
  app.Use(async (context, next) =&gt;
  {
      context.Response.Headers.Add("X-Content-Type-Options", "nosniff");
      await next();
  });
  
  // Syntax 3.
  app.Use(async (context, next) =&gt;
  {
      context.Response.Headers.Add("X-Content-Type-Options", "nosniff");
      await next.Invoke();
  });
  
  // Syntax 4.
  app.Use(next =&gt;
  {
      return ctx =&gt;
      {
          ctx.Response.Headers.Add("X-Content-Type-Options", "nosniff");
          return next(ctx);
      };
  });
  </code></pre>
  
  <p>Are they all the same?   </p>