question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why should we call the module twice?

See original GitHub issue

I have one module in my app, with the last update I should write this:

@Module({
  imports: [
    TypeOrmModule.forRoot({
      /* Connection options goes here */,
      entities: [/* Entities goes here */],
    }),
    TypeOrmModule.forFeature([/* Entities goes here */]),
  ]
})

Why? I’ve already pass my entities inside options. And now I importing the same module twice.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
FriOnecommented, Feb 16, 2018

@obedm503 yeah, I have the same thought about it. It will be great if forRoot method creates repositories for entities if they was provided as classes array. We can have both methods implemented. Also forFeature name doesn’t explain what the function actually do. It is better to call it provideRepositories or smth like that.

3reactions
fwoelffelcommented, Feb 16, 2018

What about people who:

  • uses forRoot in a DatabaseModule which exports the instanciated connection
  • uses forFeature([ User ]) in a UserModule which imports the DatabaseModule
  • uses forFeature([ Car ]) in a CarModule which imports the DatabaseModule
  • doesn’t want the Repository<User> available in the CarModule
  • doesn’t want the Repository<Car> available in the UserModule

I don’t think that what you’re asking for would allow that design.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Calling a module multiple times causing duplicate resource ...
Generally speaking, it's the responsibility of a module to ensure that it doesn't make any assumptions that would prevent it from being ......
Read more >
Terraform use case to create multiple almost identical copies ...
Creating a module is nothing special: just put any Terraform templates in a folder. What makes a module special is how you use...
Read more >
What Happens When a Module Is Imported Twice?
The rules are quite simple: the same module is evaluated only once, in other words, the module-level scope is executed just once. If...
Read more >
for_each to call terraform module multiple times - Terragrunt
Since each call is a separate module call, having each one share state will result in each call stepping over each other.
Read more >
Modules - Configuration Language | Terraform
A module can call other modules, which lets you include the child module's resources into the configuration in a concise way. Modules can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found