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.
- Convenience me to write this abstraction.
- Write implementation themself and maintain that.
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!!
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