Sunday, January 4, 2015

Assembly Neutral Interface in ASP.NET 5(vNext)


Recently Microsoft has open sourced it’s entire ASP.NET next version stack on GitHub and I have been closely watching this for a quite a some time to understand how they have created architecture of it and how they organize everything in such a large stack.

I have seen  [AssemblyNeutral] attribute in few of interfaces and I was curious why it was required. So I dig into it and learned about it.

Why we need Assembly Neutral Interfaces?

In earlier version of ASP.NET and Microsoft.NET Interfaces are bind to a assembly where it is declared. Let’s say I have written a interface under DotNetJalps namespace for my framework.
namespace DotNetJalps
{
    public interface ILogger
    {
        DoAmazingStuff();
    }
}
Now after some time this framework is super popular and everybody loves abstraction I have created and now they wants same abstraction so there are two ways we can do this.

  1. Convenience me to write this abstraction.
  2. Write implementation themself and maintain that.
Now based on super demand of Let’s say I have written a implementation of xyz logging framework so all needs of xyz framework completed. But now someone wants to write implementation for abc framework. So we ran into same problem again they have two options as we have written before.

The first option is not valid as I can not write implementation of each and every framework exists in this world and second one sucks because there will be lots of implementation of same thing and every one wants to implement this abstraction needs to maintain this.

This is a perfect scenario, where Assembly Neutral Interface can help you.

What is AssemblyNeutral Attribute?

In earlier version of .NET Framework interfaces where tied to an assembly. But when you put that AssemblyNeutral attribute. It’s identity no longer tied to an assembly. Now interfaces which are there with AssemblyNetural are just works as contracts.
namespace DotNetJalps
{
    [AssemblyNeutral]
    public interface ILogger
    {
        DoAmazingStuff();
    }
}
This will remove binary dependencies and anybody wants to implement that in their code must not think about dependencies all they need to do is a Assembly Neutral attribute.

You can fine more information about AssemblyNeutral from the following links.

http://davidfowl.com/assembly-neutral-interfaces-implementation/
https://github.com/aspnet/Home/wiki/Assembly-Neutral-Interfaces
http://blog.srulytaber.com/2014/11/duck-typing-in-aspnet-vnext/

That's it. Hope you like it. Stay tuned for more!!
Share:

1 comment:

  1. This looks clean and easy to read but won't it be weakly typed? Is this little better readability worth the trade-off? What are your thoughts?

    ReplyDelete

Your feedback is very important to me. Please provide your feedback via putting comments.

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews