Tuesday, April 3, 2018

Building Enterprise Grade Web APIs - Use Feature Folders

One of the most important attributes of any code we write is maintainability.  Over the lifetime of a piece of code, it will be debugged, modified and upgraded numerous times, often by developers who were not on the original team that wrote the code. 

One of the most important aspects of maintainability is that the developer maintaining the code needs to be able to easily find what they are looking for.  This is where feature folders come in.  When using feature folders in our API, we don't use the traditional folders named Models and Controllers.  Instead, we name our folders after the endpoints of our API (the features) and place all the code related to to that endpoint (feature) within that folder.  Here is an example:




As you have probably guessed, this is an API related to Food Trucks.  If you looked at the endpoints for the API you would see URLs like /api/FoodTrucks and /api/Locations.  It is pretty easy to guess where the code is for those endpoints, in the FoodTrucks and Locations folders respectively.  For child endpoints, that is, endpoints like /api/FoodTrucks/{foodTruckId}/Reviews, I use a dot notation on the folder name like FoodTrucks.Reviews.  As you can see though, it is very easy to map from what an endpoint is to where the code is that supports that endpoint.

As you see in the screenshot above, I have expanded the Locations folder so we can have a look inside.  We see the following:
  • The controller - LocationsController
  • The view models used by this feature - LocationModel, CreateLocationModel and UpdateLocationModel
  • Two validator classes that are used to implement validation rules related to this feature  - CreateLocationModelValidator and UpdateLocationModelValidator
  • The AutoMapper profile used to map objects related to this feature - LocationsAutoMapperProfile.
Without even looking inside the files at the code, you already have a pretty good idea about what is going on.  And you know where everything is related to this feature.  Contrast this with the traditional folder layout in MVC projects:




Here if we need to debug and then make a change to the Locations endpoint, we have to navigate multiple folders to do so.  In fact, I'm not even showing the validator classes or the AutoMapper profile classes in this screenshot because they don't fit on the screen.  Sure, we could put our validators in with our models in the ApiModels folder, but for even for this relatively API, we are starting to get some folders that are unwieldy.

There is another benefit of using feature folders.  Since all of the code used for a feature is in one folder, the folder (and thereby the namespace) forms a boundary in our code that delineates this feature.   If we find ourselves needing to reach across folders, we are crossing a boundary in our code base and we have an indication that something is wrong.  This helps to discourage us from sharing model objects across two or more controllers where the object would have more than one responsibility.  Having boundaries defined like this in our code helps us be more modular and keep everything where it belongs.

Summary

I think feature folders are the way to go.  This is a pattern that you actually see quite a bit in the Angular and React communities, and I think there is no reason not to adopt the same in ASP.NET projects.  I think we end up with a much cleaner organization of the code and it is easier to find what you are looking for.  So for your next project, give feature folders a try.  I think once you complete a project using feature folders you will agree it is the way to go.

47 comments:

  1. Really nice blog post.provided a helpful information.I hope that you will post more updates like this Ruby on Rails Online Training Hyderabad


    ReplyDelete
  2. Nice post. Very interesting and useful information you had posted. Thanks for sharing your knowledge.
    Hope it might be very useful for many people. keep on updating...!!

    Vehicle tracking system
    Fleet management software

    ReplyDelete

  3. A great article! I also have an ERP system in my company and I am very satisfied with it - zero problems.
    Now I'm wondering about the internet of things. I've seen an interesting Pro4People offer (my friends say, contact us , but I'm wondering all the time ...) . Do you know this too and you could advise me?

    ReplyDelete
  4. building enterprise grade web APIs is one of the best post

    our blog : http://www.shreeyainfotech.com

    ReplyDelete
  5. CRM Development Company
    Working with a professional CRM Development Company can mean the difference between getting it right first time, or having to rework. Who has time for that


    ReplyDelete
  6. Have you heard of the program aws cloud solutions - pro4people.com are working, amongst others, in the field of medical softwares. I believe they could greatly influence and help any establishment in prospering in a better way. It's always good to vote on the innovations.

    ReplyDelete
  7. Eumaxindia is a leading Consultant for Times of India advertisement agency in Chennai, Times of India Newspaper Ad Booking in Chennai. For more details contact us – 98404 86666

    Times of India Chennai Advertisement Booking Centre

    ReplyDelete
  8. Drive website traffic ''https://zarihz678.wixsite.com/seosolutionx'' Drive more traffic to your website has also initiated an ultimate SEO package. This package fits in the category of guaranteed quality package. This package provides everything that one could wish of. Our company’s major target is to serve small business owners.

    ReplyDelete
  9. DescriptionFIFA, also known as FIFA Football or FIFA Soccer, is a series of association football video games or football simulator, released annually by Electronic Arts under the EA Sports label. fifa 19 hack 2019

    ReplyDelete
  10. Such a nice blog. Very interesting and remarkable article. Business enterprise great web is very helpful to all.
    saas-software

    ReplyDelete
  11. If you are facing any email related issue then Dial Our AOl Email Customer Support Phone Number +(1) 844 489 7268 who Provide 24*7 Customer Support Service all over the world
    For more Information Please Visit:Email Support Number

    ReplyDelete
  12. Keto Fire Diet When you place Weight Loss strategically this can help chums do so with weight reduction. The sunlight in your eyes made a variety of lies worth believing. I guess this has a shining future. Some this case could be objectionable and allow me review our superb weight reduction plans. This essay is going to explore this quite complex enigma. This is sort of upscale, so forgive me. You don't need to know another thing germane to that. In regards to this,"Opportunity seldom knocks twice." That has been a powerful follow up.

    https://www.wellnessketoz.com/keto-fire-diet/

    ReplyDelete
  13. It is a very nice blog. Really it is a very international destination post. Thanks for sharing this post.
    Website development company in Bangladesh

    ReplyDelete
  14. Thank you so much for putting up such an interesting blog post about APIs especially REST.

    SQL Server Load Rest API

    ReplyDelete
  15. Very Informative!
    Worried About QuickBooks error,fix your error and related Problem of QuickBooks.Dial Our Toll-free Number.
    Dial QuickBooks Support Phone Number Arizona 1-844-908-0801

    ReplyDelete
  16. Very Informative!
    Worried About QuickBooks error,fix your error and related Problem of QuickBooks.Dial Our Toll-free Number.
    Dial QuickBooks for mac Support Phone Number 1-844-908-0801

    ReplyDelete
  17. Very Informative!
    Worried About QuickBooks error,fix your error and related Problem of QuickBooks.Dial Our Toll-free Number.
    Dial QuickBooks for mac Support Phone Number 1-844-908-0801

    ReplyDelete
  18. Well explained and informative blog.
    We at QuickBooks Support Phone Number USA 1-855-600-4060 committed to support the QuickBooks users as the top-most priority. Our experts are available round the clock to solve users' problems.

    ReplyDelete
  19. well Explained!
    Worried About QuickBooks error fix your error and related Problem of QuickBooks.Dial Our Toll-free QuickBooks Number.
    Dial QuickBooks Premier Support Phone Number 1-844-999-0406

    ReplyDelete
  20. Nice Blog!
    Fix QuickBooks error with Our QuickBooks expert Dial on Our toll free Number For instant and Quick Solution.
    Click Here to Know How to fix QuickBooks install error 1603 1-844-908-0801

    ReplyDelete
  21. GET  ACCESS TO ANY CELLPHONE REMOTELYHACK ANY WHATSAPP  ACCOUNT HACK ANY INSTAGRAM  ACCOUNT  HACK ANY FACEBOOK ACCOUNTUsing SS7
    GET ALL MONEY ADDERS SOFTWARE HERE WITH PROOF  
    PAYPAL MONEY ADDERPAYONEER MONEY ADDERBITCOIN MONEY ADDER
    SKRILL MONEY ADDER
    Western Union bug 
    NETELLER ADDER

    DEBIT CARD LOADER
    BANK ACCOUNT LOADER
    CREDIT CARD LOADER
    CLONE CARDS
    HACK ANY GMAIL ACCOUNTLinkedIn email and password hacking
    SS7 SOFTWARE AVAILABLESerious inquiries only
    contact me : putro9111@gmail.comTelegram:   https://t.me/Hackord247Phone:   +1 (912) 805-7496https://makemoneywithputro.wordpress.com/
     HACK N'IMPORTE QUEL COMPTE WHATSAPP
     HACKER TOUT COMPTE INSTAGRAM
     HACK N'IMPORTE QUEL COMPTE FACEBOOK
     OBTENEZ TOUS LES LOGICIELS AJOUT D'ARGENT AVEC LA PREUVE
     AJOUT D'ARGENT PAYPAL
     AJOUT D'ARGENT PAYONEER
     BITCOIN MINER BOTAJOUT D'ARGENT DE SKRILLBug de Western UnionNETELLER ADDER
     CHARGEUR DE CARTE DE DÉBIT
     CHARGEUR DE COMPTE BANCAIRE
     CHARGEUR DE CARTE DE CRÉDIT
     CARTES CLONE
     HACKER TOUT COMPTE GMAIL Piratage d'e-mails et de mots de passe LinkedIn
     LOGICIEL SS7 DISPONIBLE
     Enquêtes sérieuses uniquement
     contactez-moi: putro9111@gmail.com
     Télégramme: https://t.me/Hackord247
     Téléphone: +1 (912) 805-7496
     https://makemoneywithputro.wordpress.com/

    私に連絡してください:putro9111@gmail.com
     WHATSAPPのアカウントをハック
     インスタグラムアカウントをハックする
     Facebookアカウントをハック

     証拠のあるすべてのマネーアダーソフトウェアをここで入手する

     PAYPAL MONEY ADDER

     PAYONEER MONEY ADDER
     ビットコインマイナーボット
     SKRILL MONEY ADDER
     ウエスタンユニオンバグ
     NETELLER ADDER
     デビットカードローダー
     銀行口座ローダー
     クレジットカードローダー
     クローンカード
     Gmailアカウントをハック LinkedInのメールとパスワードのハッキング
     利用可能なSS7ソフトウェア
     深刻な問い合わせのみ
     私に連絡してください:putro9111@gmail.com
     電報:https://t.me/Hackord247
     電話:+1(912)805-7496
     https://makemoneywithputro.wordpress.com/



     
     拥有任何WHATSAPP帐户
     拥有任何INSTAGRAM帐户
     拥有任何FACEBOOK帐户

     在此处获取带有证明的所有货币添加软件

     贝宝付款
     收款人付款人
     比特币矿工机器人
     速效货币加法器
     西联汇款错误
     NETELLER ADDER
     借记卡装载器
     银行帐户装载程序
     信用卡装载机
     克隆卡
     拥有任何GMAIL帐户 LinkedIn电子邮件和密码黑客
     提供SS7软件
     仅认真查询
     与我联系:putro9111@gmail.com
     电报:https://t.me/Hackord247
     电话:+1(912)805-7496
     https://makemoneywithputro.wordpress.com/


     Взломать любой аккаунт
     Взломать любой аккаунт INSTAGRAM
     Взломать любой аккаунт в FACEBOOK
     ПОЛУЧИТЕ ВСЕ ПРОГРАММНОЕ ОБЕСПЕЧЕНИЕ ДЕНЕГ ДОБАВЛЯЕТ СЮДА
     ПОДСЧЕТ ДЕНЕГ PAYPAL
     PAYONEER MOND ADDER
     BITCOIN MINER BOT
     SKRILL MOND ADDER
     Ошибка Western Union
     NETELLER ADDER
     ПОГРУЗЧИК ДЕБЕТНОЙ КАРТЫ
     ПОГРУЗЧИК БАНКОВСКОГО СЧЕТА
     ПОГРУЗЧИК КРЕДИТНОЙ КАРТЫ
     КЛОННЫЕ КАРТЫ
     Взломать любой аккаунт GMAIL LinkedIn взлом электронной почты и паролей
     ПРОГРАММНОЕ ОБЕСПЕЧЕНИЕ SS7 В НАЛИЧИИ
     Только серьезные запросы
     свяжитесь со мной: putro9111@gmail.com
     Telegram: https://t.me/Hackord247
     Телефон: +1 (912) 805-7496
     https://makemoneywithputro.wordpress.com/
     
     HACKEN SIE JEDES WHATSAPP-KONTO
     HACKEN SIE JEDES INSTAGRAM-KONTO
     HACK JEDES FACEBOOK-KONTO
     HIER ERHALTEN SIE ALLE GELDADDERS-SOFTWARE MIT BEWEIS
     PAYPAL GELD ADDER
     PAYONEER GELDADDER
     BITCOIN MINER BOT
     SKRILL GELDADDER
     Western Union Bug
     NETELLER ADDER
     DEBIT CARD LOADER
     BANKKONTO-LADER
     KREDITKARTENLADER
     KLONKARTEN
     HACK JEDES GMAIL-KONTO LinkedIn E-Mail- und Passwort-Hacking
     SS7 SOFTWARE VERFÜGBAR
     Nur ernsthafte Anfragen
     Kontaktieren Sie mich: putro9111@gmail.com
     Telegramm: https://t.me/Hackord247
     Telefon: +1 (912) 805-7496
     https://makemoneywithputro.wordpress.com/

    ReplyDelete

  22. Lockdown is running in the whole country due to coronavirus, in such an environment we are committed to provide the best solutions for QuickBooks Support Phone Number.
    Know how to fix QuickBooks error 6240 to get in touch.
    Dial : 1-844-908-0801,1-844-999-0406.

    ReplyDelete
  23. "Runwal Avenue" offers 1 BHK and 2 BHK extravagant Apartments in Kanjurmarg(E).

    ReplyDelete
  24. Nice & Informative Blog !
    Our specialists at QuickBooks Customer Service 1-855-550-7546 guide you to properly use QuickBooks software to enhance your business in the most competitive market.

    ReplyDelete
  25. Good and very Informative article
    For a good quality website it needs to be responsive,navigation,good visuals like images or videos with purpose.We are no.1 website design and development company in Faridabad, Delhi/Ncr.We also serve social media marketing,ppc services,digital marketing,e-commerce website development,Seo services also.

    web design agency

    All around website design and development with many creative features packed.Logo design for reflect your brand.There are several attention-worthy website designs.Our Website is now even more beginner-friendly with premium plans.Cheaper or Low cost website development in region.And also a great place to start career and startups. You will be happy with what you get with your money for every one small business to big companies.Our website is scalable also.Professional domain which is quick and easy to setup.Our sites are great for SEO tools for further promotion and ranking.We are very helpful so you can create your dream website with our creative experts with 8+ years of experience. You will not miss anything with our creative staff working with you.We work and you decide the color and design of your choice so you can be the part of development.

    ReplyDelete
  26. Good and Informative article:
    website development agency
    A flexible website must be easy to extend and easy to update.knowledge in SEO, design, performance, security, support, and WordPress to help you build reliable, beautiful WordPress sites,designed in such a way that when you choose to put in an RSS feed, or send postings to Twitter, it can be accomplished quickly and easily. It's important to wrap them in a bit of HTML and use CSS to make them responsive.

    ReplyDelete
  27. You can download QuickBooks File Doctor free of cost from Intuit's official website and solve your company files errors and heal them in their best condition.

    ReplyDelete
  28. Hi, I do think this is an excellent website. I stumbledupon it ;
    ) I may revisit yet again since i have book marked it.
    Money and freedom is the greatest way to change, may
    you be rich and continue to help others.
    SEO services Pune
    social media marketing

    ReplyDelete
  29. This comment has been removed by the author.

    ReplyDelete
  30. This comment has been removed by the author.

    ReplyDelete
  31. Solution of all the problem created in quickbooks visit here quickbooks install diagnostic tool

    ReplyDelete
  32. The global Security Analytics Market size was valued at USD 7.01 billion in 2019 and is expected to grow at a compound annual growth rate (CAGR) of 14.6% from 2020 to 2027. Growing superiority in threat attacks employed by mature threat actors that remain undetected using predefined security tools or signature matching technologies is encouraging enterprises to adopt security analytics solutions. Furthermore, increasing cyber threats from advanced targeted attacks (ATA) or advanced persistent threats (APT) are driving the market. The APTs or ATAs often stay undetected and remain within the enterprise networks for a longer period of time, which, in turn, causes severe damages to the network infrastructure. Hence, the adoption of security analytics increases to detect and remediate such threats.

    ReplyDelete

  33. Quickbooks banking error 102 usually arises when the bank website is under maintenance or due to some technical glitch. Get more support to resolve Quickbooks banking error 102 at QBSsolved, give a call to 1-888-910-1619.

    ReplyDelete

  34. Many aspirants face different types of issues with errors and if anyone is facing an error regarding Quickbooks won’t open so here is your solution for that you can go through this above-mentioned page and gather the solutions

    ReplyDelete

  35. very informative blog Thanks for sharing with us .if you are Searching best quickbooks customer service then call at +18882104052 for instant result

    ReplyDelete
  36. very good post If you are looking for the right software to manage your business then contact at
    Quickbooks Customer Service(855) 738-7873

    ReplyDelete
  37. its amazing post Thanks For Sharing you can also t get best recovering solutions call us at

    Quickbooks Customer Service+18776931117

    ReplyDelete
  38. Very informative Thanks For sharing Kindly call at QuickBooks Phone Number+18552018294

    ReplyDelete
  39. Thankyou for writing an good article. I read it. You must know QB has many errors as like QuickBooks BEX error , it may pop up due to partial QB installation. If you are stuck with issue you must follow our given steps and must approch to our team at 855-738-0359.

    ReplyDelete