The bottom line is that
app and any slices you create simply act as “containers” in Hanami’s component management system. This really just means that they are namespaces that get auto-loaded when your app boots.
This section of the Hanami guides walks through the boot process and how components in the
app directory get auto-loaded.
This section discusses “containers” and the component management system in more depth. Pay attention to the section on dependency injection. Even though all of the examples use components from the
app container, you will use the same technique to access components you create in your slices.
Finally, the slices guide should pull it all together for you, particularly the section on slice imports and exports.
Here is some troubleshooting advice using the Hanami Console. In your project directory, run
bundle exec hanami console. In the console, run
Hanami.app.boot and then
Hanami.app.keys. This will show you all of the available components in the
app directory. In a new app, it will look something like this:
These are the default components. Others that you create will show up here. If you wanted to use any of these components from within a slice that you create, you could use the
include Deps “mixin.” I think it would look like this:
# From within a slice:
When you create a slice, it gets its own container. You can interact with the container in the console, just as we did with
app above. For example, if you have an Admin slice with an index action, you can view your registered components like this.
You could then access Admin slice components from another slice or from
app like this:
I’m typing most of this from memory, so I hope I haven’t gotten anything wrong here. In any event, the guides I referenced do cover this stuff and should be adaptable to your situation.
As for when and how to use slices, that is a philosophical question at heart. The thread you referenced is more of a debate over how Hanami apps might be organized. Not all of this is settled yet (at least publicly), so that thread might just be more confusing than helpful in relation to your question.
If you are coming from Rails, you might choose to keep everything in
app, and that’s just fine. If you need more robust organization, you might choose to use slices and organize them as you see fit. That kind of experimentation and exploration will help guide the direction that Hanami takes in the future.
Good luck! I’m excited about Hanami 2 and I’m glad to see others that are too.