Reusable Ash Resources

I've got a commonly-used Ash resource that I'd like to put in an Elixir package for reuse across Phoenix apps. Is anyone doing this? Can anyone point me towards examples or best practice? This works, but the otp_app is hardcoded:
defmodule Packaged.Resource do
use Ash.Resource, domain: Packaged.Domain, otp_app: :consumer_app
end
defmodule Packaged.Resource do
use Ash.Resource, domain: Packaged.Domain, otp_app: :consumer_app
end
This fails:
defmodule Packaged.Resource do
use Ash.Resource, domain: Packaged.Domain, otp_app: Application.get_application(__MODULE__)
end
defmodule Packaged.Resource do
use Ash.Resource, domain: Packaged.Domain, otp_app: Application.get_application(__MODULE__)
end
Ash compilation seems to require static configuration for otp_app. Is that right?
Solution:
that solved it for me. thanks again for the tips.
Jump to solution
6 Replies
ZachDaniel
ZachDaniel6h ago
The otp app should typically refer to the app that distributes it. Why do you need to set it to the users otp app?
andyl
andylOP6h ago
Thanks for the tip I'll give that a try...
Chaz Watkins
Chaz Watkins5h ago
I’m curious, why do we have to put otp_app on the resource?
ZachDaniel
ZachDaniel5h ago
it allows them to be configured, and tells us where to look for them in config for validating domains and stuff you don't have to have it if you don't want to
andyl
andylOP4h ago
you don't have to have it if you don't want to
Solution
andyl
andyl4h ago
that solved it for me. thanks again for the tips.

Did you find this page helpful?