# Question about dry-system and auto register

**URL:** <https://discourse.dry-rb.org/t/question-about-dry-system-and-auto-register/160>\
**Category:** Support\
**Created:** [November 19, 2016, 6:53am UTC](https://discourse.dry-rb.org/t/question-about-dry-system-and-auto-register/160 "2016-11-19T06:53:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dvallance](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/dvallance/32/64_2.png) [@dvallance](https://discourse.dry-rb.org/u/dvallance)\
**Post date:** [November 19, 2016, 6:53am UTC](https://discourse.dry-rb.org/t/question-about-dry-system-and-auto-register/160/1 "2016-11-19T06:53:39Z")

</div>

Is there a way to manipulate the component key that is generated by auto\_registrar?

…given a class that is in a deep directory structure…

```auto
# lib/company/project/interactors/users/some_worker.rb
module Company::Project::Interactors::Users
  class SomeWorker
    ...
  end
end

```

The key becomes quite long and I would like to possibly match for a pattern and replace it. Like for the above, any component identifiers with “ **company.project.interactors**.users.someworker” would be replaced simply with “ **interactors** ”. …so for the above it would be “ **interactors.users.someworker** ”

What would be the best approach here?

I see there is a AutoRegistrar class, would I have to supply my own version of this or is there a better way? Maybe somewhere else, as I see the component should already have its identifier by this point?

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/timriley/32/25_2.png) [@timriley](https://discourse.dry-rb.org/u/timriley)\
**Post date:** [November 21, 2016, 10:16am UTC](https://discourse.dry-rb.org/t/question-about-dry-system-and-auto-register/160/2 "2016-11-21T10:16:31Z")

</div>

We actually have a (relatively recently added) feature to support this very thing!

Try adding this config to your container:

```ruby
module Company
  module Project
    class Container < Dry::System::Container # or whatever your container is
      configure do |config|
        config.default_namespace = "company.project"
      end
    end
  end
end

```

This means, that when you auto-register, your `Company::Project::Interactors:Users::SomeWorker` object will be registered with a key of `"interactors.users.some_worker"`.

Let me know how this goes!

---

<div class="post-metadata">

**Author:** ![dvallance](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/dvallance/32/64_2.png) [@dvallance](https://discourse.dry-rb.org/u/dvallance)\
**Post date:** [November 21, 2016, 5:41pm UTC](https://discourse.dry-rb.org/t/question-about-dry-system-and-auto-register/160/3 "2016-11-21T17:41:17Z")

</div>

Hey Tim,

It looks like you can’t have the separator appear in the default namespace.

```auto
[59, 68] in /home/david/.gem/ruby/2.3.1/gems/dry-system-0.5.1/lib/dry/system/component.rb
   59: end
   60: 
   61: # @api private
   62: def self.ensure_valid_namespace(ns, sep)
   63: ns_name = ns.to_s
=> 64: raise InvalidNamespaceError, ns_name if ns && ns_name.include?(sep)
   65: ns_name
   66: end
   67: 
   68: # @api private
(byebug) ns_name
"carbide.domain"
(byebug) sep
"."
(byebug) ns_name.include?(sep)
true
(byebug) 

```

…so I get an InvalidNamespaceError.

---

<div class="post-metadata">

**Author:** ![dvallance](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/dvallance/32/64_2.png) [@dvallance](https://discourse.dry-rb.org/u/dvallance)\
**Post date:** [November 21, 2016, 5:54pm UTC](https://discourse.dry-rb.org/t/question-about-dry-system-and-auto-register/160/4 "2016-11-21T17:54:03Z")

</div>

…I tried using a path separator in the name\_space to follow it through. Looks like it can only work with a single name, as the components path gets separated into an array and then the array rejects anything matching the namespace.

```auto
[71, 80] in /home/david/.gem/ruby/2.3.1/gems/dry-system-0.5.1/lib/dry/system/component.rb
   71: 
   72: if keys.uniq.size != keys.size
   73: raise InvalidComponentError, name, 'duplicated keys in the name'
   74: end
   75: 
=> 76: keys.reject { |s| ns_name == s }.join(sep)
   77: end
   78: 
   79: # @api private
   80: def self.cache
(byebug) keys
["persistence", "repositories", "campaigns"]
(byebug) ns_name
"carbide/domain"
(byebug) 

```

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/timriley/32/25_2.png) [@timriley](https://discourse.dry-rb.org/u/timriley)\
**Post date:** [November 22, 2016, 4:02am UTC](https://discourse.dry-rb.org/t/question-about-dry-system-and-auto-register/160/5 "2016-11-22T04:02:10Z")

</div>

Thanks for your report, @dvallance! I guess we’ve only used single namespaces with this feature so far. I think it should be updated to work with a nested namespace – would you mind [filing an issue on dry-system](https://github.com/dry-rb/dry-system/issues) about this?

---

<div class="post-metadata">

**Author:** ![dvallance](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/dvallance/32/64_2.png) [@dvallance](https://discourse.dry-rb.org/u/dvallance)\
**Post date:** [November 22, 2016, 5:59pm UTC](https://discourse.dry-rb.org/t/question-about-dry-system-and-auto-register/160/6 "2016-11-22T17:59:04Z")

</div>

Issue submitted. …thanks Tim.

---

<div class="post-metadata">

**Author:** ![GustavoCaso](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/gustavocaso/32/86_2.png) [@GustavoCaso](https://discourse.dry-rb.org/u/GustavoCaso)\
**Post date:** [June 23, 2017, 5:53am UTC](https://discourse.dry-rb.org/t/question-about-dry-system-and-auto-register/160/7 "2017-06-23T05:53:19Z")

</div>

@dvallance These issue has been fixed. 🙂

---

<div class="post-metadata">

**Author:** ![dvallance](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/dvallance/32/64_2.png) [@dvallance](https://discourse.dry-rb.org/u/dvallance)\
**Post date:** [June 23, 2017, 4:05pm UTC](https://discourse.dry-rb.org/t/question-about-dry-system-and-auto-register/160/8 "2017-06-23T16:05:12Z")

</div>

Awesome! Thank you very much…
