Base solution for your next web application
Open Closed

Call ABPServices from Console App #9510


User avatar
0
unidata created

Hi! I'm trying to run ABP services from a console application.

I was guided by this example [https://support.aspnetzero.com/QA/Questions/9031/Accessing--DomainService-Repositories-from-outside-Web-Solution] (https://support.aspnetzero.com/QA/Questions/9031/Accessing--DomainService-Repositories-from-outside-Web-Solution), specifically using the example https://github.com/aspnetboilerplate/aspnetboilerplate-samples/blob/master/AbpEfConsoleApp/AbpEfConsoleApp/Program.cs, but I can't get it to work.

When I run it I get the following error: (VCloud is the name of my app)

> Castle.MicroKernel.Handlers.HandlerException
HResult=0x80131500
Message=Can't create component 'VCloud.VCloudCustom.Common.VCloudSettingProvider' as it has dependencies to be satisfied.
'VCloud.VCloudCustom.Common.VCloudSettingProvider' is waiting for the following dependencies:
Service 'Abp.Domain.Repositories.IRepository`2[[Abp.Configuration.Setting, Abp.Zero.Common, Version=5.4.0.0, Culture=neutral, PublicKeyToken=null],
[System.Int64, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' which was not registered.

Source=Castle.Windsor
StackTrace:
at Castle.MicroKernel.Handlers.DefaultHandler.AssertNotWaitingForDependency()
at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, Arguments additionalArguments, IReleasePolicy policy, Boolean ignoreParentContext)
at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, Arguments arguments, IReleasePolicy policy, Boolean ignoreParentContext)
at Castle.MicroKernel.DefaultKernel.Resolve(Type service, Arguments arguments)
at Castle.Windsor.WindsorContainer.Resolve(Type service)
at Abp.Dependency.IocManager.Resolve(Type type)
at Abp.Dependency.IocResolverExtensions.ResolveAsDisposable[T](IIocResolver iocResolver, Type type)
at Abp.Configuration.SettingDefinitionManager.Initialize()
at Abp.AbpKernelModule.PostInitialize()
at Abp.Modules.AbpModuleManager.<>c.b__15_2(AbpModuleInfo module)
at System.Collections.Generic.List1.ForEach(Action1 action)
at Abp.Modules.AbpModuleManager.StartModules()
at Abp.AbpBootstrapper.Initialize()
at ConsoleTesting.Program.Main(String[] args) in D:\Source\Vinson\VCloud\ConsoleTesting\Program.cs:line 27

This exception was originally thrown at this call stack:

ConsoleTesting.Program.Main(string[]) in Program.cs

This is my code of the console app what im trying to do:

> using System;
using System;

using Abp;
using Abp.Dependency;
using Abp.Castle.Logging.Log4Net;

using Castle.Facilities.Logging;
using VCloud;
using VCloud.Rtdm.CashAudit;

namespace ConsoleTesting
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Starting");
 //Bootstrapping ABP system
        //using (var bootstrapper = AbpBootstrapper.Create<MyConsoleAppModule>())
        using (var bootstrapper = AbpBootstrapper.Create<VCloudApplicationModule>())
        {
            bootstrapper.IocManager
                .IocContainer
                .AddFacility<LoggingFacility>(f => f.UseAbpLog4Net().WithConfig("log4net.config"));
            bootstrapper.Initialize();

            //Getting a Tester object from DI and running it
            using (var tester = bootstrapper.IocManager.ResolveAsDisposable<RtdmCashAuditService>())
            {
                var r = tester.Object.Test();
                Console.WriteLine(r);
            } //Disposes tester and all it's dependencies

            Console.WriteLine("Press enter to exit...");
            Console.ReadLine();
        }
    }
}
>
> 
> }

5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi

    The VCloudApplicationModule seems to be missing some dependencies on other modules.

    You should use MyConsoleAppModule and depend on some modules in MyConsoleAppModule, you can refer to the WebMvcModule and WebCoreModule.

  • User Avatar
    0
    unidata created

    Thanks for your answer!

    Make the changes you mention and get it to move forward in the execution and now I get another error, always within the so-called

    bootstrapper.Initialize();
    
    Can't create component 'Abp.BackgroundJobs.BackgroundJobStore' as it has dependencies to be satisfied.
    

    Is there any way I can avoid trying to set up the Backgroudjob? Try this setting and it gives me the error I indicate.

    Configuration.BackgroundJobs.IsJobExecutionEnabled = false;
    

    This is the complete exception

    Castle.MicroKernel.Handlers.HandlerException
      HResult=0x80131500
      Message=Can't create component 'Abp.BackgroundJobs.BackgroundJobStore' as it has dependencies to be satisfied.
    
    'Abp.BackgroundJobs.BackgroundJobStore' is waiting for the following dependencies:
    - Service 'Abp.Domain.Repositories.IRepository`2[[Abp.BackgroundJobs.BackgroundJobInfo, Abp, Version=5.4.0.0, Culture=neutral, PublicKeyToken=null],[System.Int64, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' which was not registered.
    
      Source=Castle.Windsor
      StackTrace:
       at Castle.MicroKernel.Handlers.DefaultHandler.AssertNotWaitingForDependency()
       at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
       at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
       at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
       at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernelByType(CreationContext context, ComponentModel model, DependencyModel dependency)
       at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.ResolveFromKernel(CreationContext context, ComponentModel model, DependencyModel dependency)
       at Castle.MicroKernel.Resolvers.DefaultDependencyResolver.Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
       at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateConstructorArguments(ConstructorCandidate constructor, CreationContext context)
       at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.Instantiate(CreationContext context)
       at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context)
       at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden)
       at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally)
       at Castle.MicroKernel.Lifestyle.SingletonLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy)
       at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
       at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
       at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
       at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, Arguments additionalArguments, IReleasePolicy policy, Boolean ignoreParentContext)
       at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, Arguments arguments, IReleasePolicy policy, Boolean ignoreParentContext)
       at Castle.MicroKernel.DefaultKernel.Resolve(Type service, Arguments arguments)
       at Castle.Windsor.WindsorContainer.Resolve[T]()
       at Abp.Dependency.IocManager.Resolve[T]()
       at Abp.AbpKernelModule.PostInitialize()
       at Abp.Modules.AbpModuleManager.<>c.b__15_2(AbpModuleInfo module)
       at System.Collections.Generic.List`1.ForEach(Action`1 action)
       at Abp.Modules.AbpModuleManager.StartModules()
       at Abp.AbpBootstrapper.Initialize()
       at ConsoleTesting.Program.Main(String[] args) in D:\Source\Vinson\VCloud\ConsoleTesting\Program.cs:line 25
    
      This exception was originally thrown at this call stack:
        [External Code]
        ConsoleTesting.Program.Main(string[]) in Program.cs
    
  • User Avatar
    0
    maliming created
    Support Team

    hi

    You can refer to this demo.

    https://github.com/aspnetzero/aspnet-zero-samples/blob/master/ConsoleAppDemo

    https://github.com/aspnetzero/aspnet-zero-samples/blob/master/ConsoleAppDemo/src/ConsoleAppDemo.ConsoleApplication/ConsoleAppDemoConsoleApplicationAppModule.cs

  • User Avatar
    0
    PangeaGS created

    Hello guys, having the same task and the same issue. Link on ConsoleAppDemo returns 404. Do you have another link?

  • User Avatar
    0
    maliming created
    Support Team

    hi PangeaGS

    Please try add your github user to zero organization, then you can access the link.

    https://aspnetzero.com/LicenseManagement