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

Add forRootAsync for configuration via configService #36

Open
DimosthenisK opened this issue Sep 24, 2019 · 3 comments
Open

Add forRootAsync for configuration via configService #36

DimosthenisK opened this issue Sep 24, 2019 · 3 comments

Comments

@DimosthenisK
Copy link

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Currently, it's only possible to instantiate the module via the .withConfig method. It is not possible to inject a service into this method, so it is impossible to use a config service for the module instantiation.

Expected behavior

Enable both the .withConfig method and a factory-pattern method, that allows dependency injection.

What is the motivation / use case for changing the behavior?

I don't want to use process.env variables as all my config logic is inside a config module. It is possible to override this behavior by manually injecting all config values into process.env, but this seems like a bad choice.

Environment


Nest version: 6.6.0

 
For Tooling issues:
- Node version: 12  
- Platform: Windows 

Others:

@manekinekko manekinekko self-assigned this Oct 1, 2019
@DimosthenisK
Copy link
Author

DimosthenisK commented Oct 1, 2019

Hey, just for a notice, I went ahead and bypassed this.
I created a wrapper module, and I instanciate the DynamicModule from it.

import * as azure from '@nestjs/azure-storage';

export const AZURE_STORAGE_MODULE_OPTIONS = azure.AZURE_STORAGE_MODULE_OPTIONS;

@Module({
    providers: [
        azure.AzureMulterStorageService,
        azure.AzureStorageService,
    ],
    exports: [
        azure.AzureMulterStorageService,
        azure.AzureStorageService,
        azure.AZURE_STORAGE_MODULE_OPTIONS,
    ],
})
export class AzureModule {
    static withConfig(
        optionsProvider: Provider<azure.AzureStorageOptions>
    ): DynamicModule {
        return {
            module: AzureModule,
            providers: [optionsProvider],
        };
    }
}

@manekinekko
Copy link
Collaborator

Interesting. Thanks for sharing.

@ksivamuthu
Copy link
Contributor

@manekinekko I've added PR to this issue. Please review and let me know your suggestions.

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

No branches or pull requests

3 participants