Base solution for your next web application
Open Closed

Self hosted WEB Api project #4998


User avatar
0
girishhande created

Hello,

I want to create a self hosted web api project instead of a dll(dynamic web api) what is default in Asp.net zero with MVC and Jquery template. I tried to create it by adding a new Web Api project, but ended up with various dependency resolution issues like . I tried to make my new web api project pretty much similar to default web api(class library) project but no luck.

Please let me know if there is any template I can refer for self hosted api for asp.net zero. Or can I use default class library web api to host independently by some way?

Regards, Girish.


3 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    the only issue you could fall into can be registering dependency system. The new project you create is considered to be a module according to ABP's literature. See the module docs

    Roughy;

    • Create a new class in the root of your project called YourWebApiModule.cs. Add the below content to your class. This will register your application to ABP Framework.
    • The keypoint is; you have to add all your dependant projects to the DependsOn attribute. For the example I only add YourProjectWebCoreModule
    [DependsOn( typeof(YourProjectWebCoreModule))]
        public class YourWebApiModule: AbpModule
        {
            public override void Initialize()
            {
                IocManager.RegisterAssemblyByConvention(typeof(YourWebApiModule).GetAssembly());
            }
        }
    

    You can follow *.Web.Host project to see how a WebApi is registered to dependency.

  • User Avatar
    0
    girishhande created

    I tried to implement it as you suggested, but ended up with many issues. Could you share some link or sample code?

  • User Avatar
    0
    alper created
    Support Team

    see the *.Web.Host project in your solution. Each project is a module in your solution. You have to read this doc <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Module-System">https://aspnetboilerplate.com/Pages/Doc ... ule-System</a>