Tutorial :Writing API in C# for My Application



Question:

I'll write a application but I've never experienced to allow people to use my application programming interface before.I mean how kinda design I should make to let people use my methods from outside world like API.

Please some one show me a way.I am kinda new to this.


Solution:1

  1. Expose as little as you can. Every bit you publish, will return to you x100 in next version. Keeping compatibility is very hard.
  2. Create abstractions for everything you publish. You will definitely change your internals, but your existing users should stay compatible.
  3. Mark everything as internal. Even the main method of your application. Every single method that could be used, will be used.
  4. Test your public API the same way you would for interfaces. Integration tests and so on. Note that your API will be used in unpredictable ways.
  5. Maximize convention over configuration. This is required. Even if your API is a single method you will still need to support this. Just makes your life easier.
  6. Sign, and strong name your assemblies, this is good practice.
  7. Resolve as many FxCop and StyleCop errors as possible.
  8. Check your API is compatible with the Naming Guidelines of your platform.
  9. Provide as many examples as you can, and remember that most of the usage of your API will be Ctrl+C and Ctrl+V from these examples.
  10. Try to provide documentation. Check that you do not have GhostDoc-style auto-generated documentation. Everybody hates this.
  11. Include information on how to find you.
  12. Do not bother with obfuscation. This will help you and your users.

ADDED

  1. API should have as less dependencies as you can. For example, dependecies on the IoC containers should be prohibited. If your code uses it internally. Just ilmerge them into your assemblies.


Solution:2

It may not be the funniest reading, and certainly not the only reading to do on the subject, but while designing your class library (your API), do check in with the Design Guidelines for Developing Class Libraries every now and then, it's a good idea to have a design that corresponds a bit with the .NET Framework iteself.


Solution:3

Make your methods you want to expose to the outside world public.


Solution:4

I found this presentation to be particularly insightful:

How to Design a Good API and Why it Matters
http://lcsd05.cs.tamu.edu/slides/keynote.pdf


Solution:5

One way to do it is to create a DLL for your main functionality that others will use and an EXE that calls the methods in the DLL. If you want your application to support plug-ins, have a look at the System.AddIn namespace.


Solution:6

If you want to see what's new in this area, check out the Managed Extensibility Framework. It's a new/"unified (see the comments...)" method for exposing features for add-ins and other extensibility/modularity.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »