DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Loading Web API Controllers from a separate library when Self Hosting Web API

Loading Web API Controllers from a separate library when Self Hosting Web API

Ovais Mehboob Ahmed Khan user avatar by
Ovais Mehboob Ahmed Khan
·
Nov. 03, 13 · Interview
Like (2)
Save
Tweet
Share
17.15K Views

Join the DZone community and get the full member experience.

Join For Free

when self hosting web api, we have to create controllers on
the same project, otherwise it does not detect the libraries even if we
reference the web api project where we have all the controllers and classes
defined.

for example, if we have a web api project that was hosted
over iis earlier, and we decided to self host it on a windows service project or
a console application, we have to copy-paste or drag/drop the classes from the
web api project to self host the web api project and also have to change its
namespace so it could be searchable by the web api framework. but what if we
have a centralized project where we have all the controllers in place and we
want the self hosted web api project to load all the controllers from there.

in order to overcome this scenario, we can create a custom
assembly resolver to say selfhostassemblyresolver and replace the default one with
this. selfhostassemblyresolver should be derived from iassemblyresolver and
then implement the getassemblies method that loads the assemblies from
particular path.

so first, create a custom assembly resolver


in the below code, where you are initializing the self host web api,
replace the default assembly resolver with your custom assembly resolver using
httpselfhostconfiguration object.


in the above code snippet, demowebapi.dll is the main web
api project i was using initially, that had used the default web api hosting on
iis.

happy coding!



Web API Web Service API Self (programming language) Library

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Top Authentication Trends to Watch Out for in 2023
  • PHP vs React
  • Core Machine Learning Metrics
  • 7 Awesome Libraries for Java Unit and Integration Testing

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: