antosubash / blog-comments

MIT License
0 stars 0 forks source link

posts/abp-module-to-microservice #12

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Add a new Module and convert it to a microservice in ABP

In this post we will see how to create a modular abp application and convert it to microservice. We will add a new module to tiered abp app and then use the separate database to store the modules data and then convert the module to a microservice..

https://blog.antosubash.com/posts/abp-module-to-microservice

fmontazeri commented 2 years ago

Hi , I've got an error when I want to use an app service named IPostAppService in the ConsoleClientDemo .

System.NullReferenceException: Object reference not set to an instance of an object.
   at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.get_ClientOptions()
   at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync(ClientProxyRequestContext requestContext)
   at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync[T](ClientProxyRequestContext requestContext)
   at Volo.Abp.Http.Client.DynamicProxying.DynamicHttpProxyInterceptorClientProxy`1.CallRequestAsync[T](ClientProxyRequestContext requestContext)
   at Volo.Abp.Http.Client.DynamicProxying.DynamicHttpProxyInterceptor`1.CallRequestAsync[T](ClientProxyRequestContext context)
   at Volo.Abp.Http.Client.DynamicProxying.DynamicHttpProxyInterceptor`1.GetResultAsync(Task task, Type resultType)
   at Volo.Abp.Http.Client.DynamicProxying.DynamicHttpProxyInterceptor`1.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo)
   at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue`1.ProceedAsync()
   at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation)
   at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter`1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func`3 proceed)
   at ConsoleClientDemo.ClientDemoService.TestContentService() in C:\git\company\company.api\applications\ConsoleClientDemo\ClientDemoService.cs:line 55

This is PostController in HttpApi library :

[Area(contentRemoteServiceConsts.ModuleName)]
[RemoteService(Name = contentRemoteServiceConsts.RemoteServiceName)]
[Route("api/postManagement/posts")]
public class PostsController :  contentController , IPostAppService
{....}

This is my HttpClientAppModule :

[DependsOn(
    typeof(ContentApplicationContractsModule),
    typeof(AbpHttpClientModule))]
public class contentHttpApiClientModule : AbpModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        context.Services.AddHttpClientProxies(typeof(ContentApplicationContractsModule).Assembly,
        contentRemoteServiceConsts.RemoteServiceName); // ModuleName & RemoteServiceName : ContentService
            Configure<AbpVirtualFileSystemOptions>(options =>
        {
            options.FileSets.AddEmbedded<contentHttpApiClientModule>();
        });

    }
}

And ConsoleClientDemo appSettings:

{
  "RemoteServices": {
    "Default": {
      "BaseUrl": "http://localhost:5201/"
    },
    "ContentService": {
      "BaseUrl" : "http://localhost:5201/"  // it's related to my content service
    }
  },

This is ConsoleClientDemoModule file:

    [DependsOn(
        typeof(AbpAutofacModule),
        typeof(AbpHttpClientIdentityModelModule),
        typeof(AbpIdentityHttpApiClientModule),
        typeof(contentHttpApiClientModule),
        typeof(AbpTenantManagementHttpApiClientModule)
        )]
    public class ConsoleClientDemoModule : AbpModule
    {

    }

content is the name of module that owns post model and implements IPostAppService

Thanks in advance