Search code examples
aspnetboilerplateabp-framework

Third party API and IHostingEnvironment in Application layer?


I have 2 queries related to the open source version of aspnetboilerplate.

  • If I am implementing some services that will call some other third party API APIs, where do I implement those? In application layer directly or Do the code for calling third party API in Core layer and then expose them as service using application layer?
  • How do i get IHostingEnvironment .EnvironmentName in Application and core layer? Based on the Environment, i need to call the API keys stored in appsettings.json Thanks.

Solution

    • use appservices for your third party integration.
    • you cannot use web based references (eg: IHostingEnvironment) in Application or Core layer. This breaks layer isolation. you can use appsettings.Development.json or appsettings.Staging.json for your different environments. asp.net automatically reads settings from the corresponding environment. but if you have extra requirement that's related to web layer. you can pass it as a parameter to your appservice method from web layer.