Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Console App #136


User avatar
0
mohammed al-qaisi created

Hi All;

I'm so interested to use this framework in all my next project , so i download the template from the site

i trying to add Console app to "SimpleTaskSystem" but always i face the same problem

<span style="color:#FF0000">The Error</span> An unhandled exception of type 'Castle.MicroKernel.ComponentNotFoundException' occurred in Castle.Windsor.dll

Additional information: No component for supporting the service SimpleTaskSystem.ConsoleApp.testClass was found

<span style="color:#FF0000">The Code</span>

namespace SimpleTaskSystem.ConsoleApp
{
    public class Program
    {
        static void Main(string[] args)
        {
            using (var bootstrapper = new AbpBootstrapper())
            {
                bootstrapper.Initialize();
                var tester = IocManager.Instance.Resolve<testClass>();
                tester.LoadAllPeopleAsync();
                Console.ReadLine();
            }
        }
    }
    public partial class testClass
    {
        private readonly IPersonAppService _personAppService;
        public testClass(IPersonAppService personAppService)
        {
            _personAppService = personAppService;
        }
        public async void  LoadAllPeopleAsync()
        {
            var result = await  _personAppService.GetAllPeople();
            foreach (var person in result.People)
            {
                Console.WriteLine(person.Name);
            }
        }
    }
}

Is there any thing to do with this issue.... :(


4 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Thanks a lot.

    First, you should desing a module (see <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Module-System">http://www.aspnetboilerplate.com/Pages/ ... ule-System</a>) as shown below:

    [DependsOn(typeof(SimpleTaskSystemDataModule), typeof(SimpleTaskSystemApplicationModule))]
        public class MyConsoleAppModule : AbpModule
        {
            public override void Initialize()
            {
                IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
            }
        }
    

    Second, your testClass should be registered to Dependency Injection (see <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Dependency-Injection">http://www.aspnetboilerplate.com/Pages/ ... -Injection</a>). Easiest way is to implement ITransientDependency as shown below:

    public partial class testClass: ITransientDependency
    { 
        ...
    }
    

    Lastly, you code can not work since you're calling an async method in sync context. This is not about ABP. Do this:

    AsyncHelper.RunSync(() => tester.LoadAllPeopleAsync());

    Also you may have to define "public async void LoadAllPeopleAsync()" as "public async Task LoadAllPeopleAsync()"

    Then it will probably work if I can not see any other problems.

    If you can not run it, I may consider to add a console app inside solution.

  • User Avatar
    0
    mohammed al-qaisi created

    Im very thankful :D hopefully this will work

  • User Avatar
    0
    hikalkan created
    Support Team

    Finished console application (<a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate-samples/commit/1af6af04c766c939a1391287fa3195134ce80745">https://github.com/aspnetboilerplate/as ... 134ce80745</a>).

    Get from github again and run it (after inserting some tasks to database).

  • User Avatar
    0
    mohammed al-qaisi created

    Wonderful .... Thanks again :D