I'm writing some testing code in an ASP.NET core MVC application. In the default Startup.cs
it uses MVC like following:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseMvc(routes => { /* ... */ });
}
Check the source code we can see .UseMvc
is an extension method of IApplicationBuilder
.
Now I want to add swagger support to this project. There is now a pre-release version, I added the reference, and now I can use:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseMvc(routes => { /* ... */ });
app.UseSwagger(...);
}
But wait! I didn't add any using
statements before use .UseSwagger
! And then I found the tricky thing: In the referenced swagger library they have a namespace called Microsoft.AspNetCore.Builder
, which is IApplicationBuilder
belongs to (in another library), so this namespace is absolutely "using" in Startup.cs
.
I'd admit it's a clever way, users will not waste their time on looking for the extension method's namespace (even nowadays VS2015 can detect extension methods' namespace but imagine other IDE e.g. VS CODE). But is there any risk to add a totally unrelated namespace CompanyB.ProjectB.XXX
in CompanyA.ProjectA.XXX.dll
?