Working with our domain & resources in code *can* be done the long form way, by building changesets/queries/action inputs and calling the relevant function in `Ash`. However, we generally want to expose a well defined code API for working with our resources. This makes our code much clearer, and gives us nice things like auto complete and inline documentation.
With these definitions, we can now do things like this:
```elixir
tweet = MyApp.Tweets.tweet!("My first tweet!", actor: user1)
comment = MyApp.Tweets.comment!(tweet.id, "What a cool tweet!", actor: user2)
```
## Configuring Cross-cutting Concerns
### Built in configuration
`Ash.Domain` comes with a number of built-in configuration options. See `d:Ash.Domain` for more.
For example:
```elixir
defmodule MyApp.Tweets do
use Ash.Domain
resources do
resource MyApp.Tweets.Tweet
resource MyApp.Tweets.Comment
end
execution do
# raise the default timeout for all actions in this domain from 30s to 60s
timeout :timer.seconds(60)
end
authorization do
# disable using the authorize?: false flag when calling actions
authorize :always
end
end
```
### Extensions
Extensions will often come with "domain extensions" to allow you to configure the behavior of all resources within a domain, as it pertains to that extension. For example:
```elixir
defmodule MyApp.Tweets do
use Ash.Domain,
extensions: [AshGraphql.Domain]
graphql do
# skip authorization for these resources
authorize? false
end
resources do
resource MyApp.Tweets.Tweet
resource MyApp.Tweets.Comment
end
end
```
### Policies
You can also use `Ash.Policy.Authorizer` on your domains. This allows you to add policies that apply to *all* actions using this domain. For example:
```elixir
defmodule MyApp.Tweets do
use Ash.Domain,
extensions: [Ash.Policy.Authorizer]
resources do
resource MyApp.Tweets.Tweet
resource MyApp.Tweets.Comment
end
policies do
# add a bypass up front to allow administrators to do whatever they want