Open Closed

Problem with ngrx effect registration #8189


0
mhrabak created

Hi guys, we are facing an issue when we register ngrx effect with injected service (generateg using nswag). when we register effect into root module angular throws exception because abp config is not yet loaded properly because app_initializer is not probably yet finished or effect is registered earlier we can not find a way how to obtain this issue unfortunately. We are quite new in angular.

Do you have any advices pleaee thanks.

we are using latest aspnetzero web api & angular 8 template.

thanks a lot.


13 Answer(s)
  • 0
    mhrabak created

    Hi guys. Any advices here? I think ngRx is used a lot in Angular so it would be desirable to make this work properly. Thanks in advance.

  • 0
    musa.demir created
    Support Team

    Hi @mhrabak

    It is not currently implemented but I'll try to help you if you can provide a recurring project using a demo project. (Can you please delete all bin, obj and node_modules folders before you publish it)

  • 0
    mhrabak created

    Hi @demirmusa, Sorry for delayed answer. We had lot of work before holidays. I have created a sample for you NgrxSample It was uploaded to our czech sharing website - you can downlaod it using slow download without creating an account. When you will have problem to download the file just tell me I will upload it elsewhere. Steps to simulate:

    • In Visual studio open NgrxSampleDemo.Web.sln
    • Run Update-Database command in Nuget Package Manager console
    • Run NgrxSampleDemo WebAPI
    • Open NgrxSampleDemo angular app
    • Run angular app (npm i, npm start)
    • Login page does not show up and in Developer tools (Ctrl+Shift+I or F12 key) console you can see an error
    • When you comment out line 322 in root.module.ts everything works OK (except dispatching data to ngrx state of course)

    Just to mention when we register Effect into lazy loaded module and register it as feature it works OK without any problem but we need to dispatch ngrx store in RootModule too.

    Thansk for help.

  • 0
    ismcagdas created
    Support Team

    Hi @mhrabak

    Thank you for sharing the project. I removed the download link since the urls in this website is public and everyone can download the source code. I downloaded the source code. I will check the problem and inform you if you haven't solved the project.

  • 0
    ismcagdas created
    Support Team

    This issue is closed because it has not had recent activity for a long time.

  • 0
    mhrabak created

    Hi guys, How could you close problem which lies on you? I gave you sample project with simulated problem and expect an answer different from closing the issue. Maybe link to another similar related issue where this would be solver or someting like that maybe.

    Thanks for answer.

  • 0
    ismcagdas created
    Support Team

    Hi @mhrabak

    You are right, this issue shouldn't be closed. I couldn't find your email. Did you send it to info@aspntezero.com ? If so, which email you sent from ?

    Thanks,

  • 0
    mhrabak created

    Hi @ismcagdas, No I gave you link to sharing website and you answered me this month ago (just 4 comments above):

    Hi @mhrabak

    Thank you for sharing the project. I removed the download link since the urls in this website is public and everyone can download the source code. I downloaded the source code. I will check the problem and inform you if you haven't solved the project

  • 0
    ismcagdas created
    Support Team

    Hi,

    Sorry It seems like I don't have the project at the moment. Could you send it to info@aspntezero.com agian ?

    Thanks,

  • 0
    mhrabak created

    Hi @ismcagdas, My colleague should sent you sample to info@aspnetzero.com on 26th February 2020. He used Id of this ticket.

    Thanks.

  • 0
    ismcagdas created
    Support Team

    Hi @mhrabak

    Thanks, I got the project. I will get back to you soon.

  • 0
    gjubber created

    I have just encounter this myself. Has any progress been made on this?

    Cause The problem seems to be caused by the service proxy being initialized before the API_BASE_URL has been set. This seems to cause a knockon effect on any other service proxy injected into a constructor. In practice this leads to all proxy calls going to undesireable domains and that is why nothing loads because the endpoints are invalid.

    Source: service-proxies.ts:

    export const API_BASE_URL = new InjectionToken<string>('API_BASE_URL');
    

    Workaround I have found a workaround to this for now, but I don't know if this has severe side effects yet. On your ngRx Effect instead of injecting your service proxy in the constructor inject an Injector and for convenience use an accessor to keep your code the same.

    I.e. Instead of

    constructor(private actions$: Actions, private demoService: DemoServiceProxy) {}
    

    use

    
        get demoService(): DemoServiceProxy {
            const { injector } = this;
            return injector.get(DemoServiceProxy);
        }
    
        constructor(private actions$: Actions, private injector: Injector) {}
    
  • 0
    ismcagdas created
    Support Team

    Hi @gjubber

    At that time, we couldn't find a better solution. If you can share a reproduction project with info@aspnetzero.com we can take a look at it again.

    Thanks for sharing the workaround.