6

Using katana, why does the Startup class should not implement a respective interface, like for example:

interface IStartup
{
  void Configuration(IAppBuilder app);
}

public class MyStartup : IStartup
{
    public void Configuration(IAppBuilder app)
    {
       ...
    }
}

I think that it could be much more intuitive for the developers to understand what they should provide with to the WebApp.Start<T> method as the T argument instead of guessing and looking for examples, it should be more explicit:

public void Start<T>() where T : IStartup
Yair Nevet
  • 12,725
  • 14
  • 66
  • 108

1 Answers1

5

The reason is "there's NO GOOD reason". Interfaces exist to communicate structure and purpose to an implementer (abstract classes do this as well, along with providing some minimal behavior). Without them, we're left with convention. In this case, by not constraining TStartup, OWIN is allowing you to use any nonsense Startup class and can only tell you at runtime if it will work. For example:

WebApp.Start<string>(BaseAddress);

This compiles fine but throws an EntryPointNotFoundException at runtime (No 'Configuration' method was found in class 'System.String).

Not to get all philosophical, but I see this as a general trend in computing today. REST, with it's no contracts, no guarantees, you figure it out paradigm is in; SOAP is out. In some ways this is a good thing, but I don't think this example is one of them.

  • Thanks for answer and sorry for the late response. – Yair Nevet Jul 09 '15 at 06:29
  • This does allow OWIN to be extended in the future without breaking existing code. The only way to do that with interfaces is to version them which also has pros and cons. – bikeman868 Sep 21 '16 at 21:58
  • This looks like golang interfaces philosophy: no class implements any interface explicitly, but rather if a class corresponds to some interface, then the class automatically implements it – manda Oct 22 '18 at 11:01