Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion content/v2.2/app/app-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ Sets the keys for the app components to be automatically imported into each slic

### `no_auto_register_paths`

Sets an array of paths (relative to the root of the app or any slice) to be excluded from component auto-registration. Defaults to `["entities"]`. See the [containers and components guide](/v2.2/app/container-and-components) for more detail.
Sets an array of paths to be excluded from component auto-registration. Defaults to `["db", "entities", "relations", "structs"]`. Note that files in `lib/` are always excluded from auto-registration, too. These paths are all relative to the root of the app or any slice. See the [containers and components guide](/v2.2/app/container-and-components) for more detail.


## Router

Expand Down
10 changes: 8 additions & 2 deletions content/v2.2/app/container-and-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ end

If you have a whole class of objects that shouldn't be placed in your container, you can configure your Hanami application to exclude an entire directory from auto registration by adjusting its `no_auto_register_paths` configuration.

Here for example, the `app/structs` directory is excluded, meaning nothing in the `app/structs` directory will be registered with the container:
Here for example, the `app/values` directory is excluded, meaning nothing in the `app/values` directory will be registered with the container:

```ruby
# config/app.rb
Expand All @@ -333,11 +333,17 @@ require "hanami"

module Bookshelf
class App < Hanami::App
config.no_auto_register_paths << "structs"
config.no_auto_register_paths << "values"
end
end
```

Note that the default value for `no_auto_register_paths` is `["db", "entities", "relations", "structs"]`,
so you do not need to specify those. Also, be sure to append to that list.

These apply for the root of the application, as well within any slices.
Copy link
Member

@timriley timriley Mar 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should link to the "slices" guide here. If a reader is going through the docs in rough order of appearance, they won't have got to slices yet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, added!

This makes me think we should consider re-ordering the guides, as well (perhaps on the new site). The current order is: Booting, Container and components, Providers, Settings, Autoloading, Environments, App config, Inflector, Code reloading, Slices.

Slices are more core than code reloading, or the inflector IMO. I think Autoloading and Environments could be lower as well. Perhaps: Booting, Container and components, Providers, Settings, App config, Slices, Autoloading, Environments, Inflector, Code reloading?

I still think linking to Slices is a good idea regardless of the order.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cllns :) Agree that it'd be worth trying a different order. We came up with this order years ago for 2.0 and haven't reconsidered it since. I think an "Overview" page for the App guide would be useful thing to have too. That way we can introduce all the key concepts in relation to each other, and provide relevant jumping off links to learn more.

Additionally, the `config/` directory within a slice is always excluded from auto-registration.

A third alternative for classes you do not want to be registered in your container is to place them in the `lib` directory at the root of your project.

For example, this `SlackNotifier` class can be used anywhere in your application, and is not registered in the container:
Expand Down