Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property injection not work #19869

Closed
1 task done
v2codes opened this issue May 20, 2024 · 7 comments
Closed
1 task done

Property injection not work #19869

v2codes opened this issue May 20, 2024 · 7 comments

Comments

@v2codes
Copy link

v2codes commented May 20, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Description

Thanks to Abp's excellent design and implementation. I've been using ABP for web.
Recently, I integrate ABP modules into the WPF project.
The properties of ApplicationService and BasicRepositoryBase always null.
It seems that AutoFac's Property Injection is not working.
Asking help to solve this, thanks a lot !

Exception:
image

Project Structure:
image

Program main entry:

 var builder = Host.CreateApplicationBuilder(args);

_abpApplication = await builder.Services.AddApplicationAsync<NCWpfAppModule>(options =>
{
    options.UseAutofac();
    options.Services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true));
    options.Services.AddHostedService<NCWpfAppHostedServcie<App, LoginWindow>>();
    options.Services.AddRegion().AddMvvm();
});

_host = builder.Build().UseRegion();
await _host.InitializeAsync();
await _host.RunAsync();
return 0; 

AppModule:

[DependsOn(typeof(AbpAutofacModule),
               typeof(NCWpfFrameworkModule),
               typeof(NCWpfHomeModule),
               typeof(NCWpfEntityFrameworkCoreModule),
               typeof(AbpEntityFrameworkCoreSqlServerModule),
               typeof(NCWpfApplicationContractsModule),
               typeof(NCWpfApplicationModule))]
    public class NCWpfAppModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            Configure<AbpDbContextOptions>(options =>
            {
                options.UseSqlServer();
            });
        }
    }

Version

v8.1.3

User Interface

Common (Default)

Database Provider

EF Core (Default)

Operation System

Windows (Default)

@v2codes v2codes added the bug label May 20, 2024
@maliming
Copy link
Member

Can you reproduce this with less code?

@v2codes
Copy link
Author

v2codes commented May 21, 2024

Can you reproduce this with less code?

Thank you , In the following repository, dev branch.
https://github.com/v2codes/NC.Wpf.Framework/tree/dev

@maliming
Copy link
Member

hi

Can you use a simple project?

Such as ABP WPF project.
https://docs.abp.io/en/abp/latest/Startup-Templates/WPF

@v2codes
Copy link
Author

v2codes commented May 22, 2024

There is no problem with Property Injection when using templates. It should be some problems with the way I use IHost startup. But there is another problem with the template. After called the Repository query method, it gets stuck. SQL was output in the log, there is no exception and any response.
Simple project is in the branch abp-wpf-template:
https://github.com/v2codes/NC.Wpf.Framework/tree/abp-wpf-template

@maliming
Copy link
Member

After called the Repository query method, it gets stuck. SQL was output in the log, there is no exception and any response.

var result = AsyncHelper.RunSync(() => _sampleAppService.GetAsync());

The property injects of SampleAppService works.

@v2codes
Copy link
Author

v2codes commented May 22, 2024

After called the Repository query method, it gets stuck. SQL was output in the log, there is no exception and any response.

var result = AsyncHelper.RunSync(() => _sampleAppService.GetAsync());

The property injects of SampleAppService works.

I solved the Property Injection problem by referring to the Program.cs in the console template.
Like this:
image

@maliming maliming removed the bug label May 22, 2024
@v2codes
Copy link
Author

v2codes commented May 22, 2024

@maliming Thanks a lot, everything is all right!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants