Skip to content

Modules and dependencies ​

Move the greeting into its own folder, export the names the application needs, and choose the implementation in main.aug.

Create a greeting folder beside main.aug:

text
hello/
  main.aug
  greeting/
    export.aug
    greeter.aug

main.aug

aug
import Greeter and FriendlyGreeter from greeting

implement Greeter with FriendlyGreeter
resolve Greeter to greeter
print(value=greeter.greet(name="August"))

greeting/export.aug

aug
export Greeter from greeter
export FriendlyGreeter from greeter

greeting/greeter.aug

aug
/** Provide a greeting for a named person. */
interface Greeter:
    greet(string name) returns string

FriendlyGreeter() implements Greeter:
    greet(string name):
        return "Hello, " + name + "!"

Run aug check . and aug run .. The output is Hello, August!.

Choose what the folder exposes ​

export.aug is the folder's public boundary. A file outside greeting can import the names listed there. It cannot reach other declarations in that folder merely by knowing their paths. Within a folder, sibling files also need explicit imports. A folder without export.aug exposes no names across its boundary.

Try removing the export line for FriendlyGreeter. The import in main.aug should fail. Restore it after running aug check .. Names beginning with _ are private and cannot be exported.

Select behavior at startup ​

Greeter declares the greeting operation. FriendlyGreeter implements it. implement Greeter with FriendlyGreeter selects the provider, and resolve Greeter to greeter obtains it for startup work.

Elsewhere in an application, injected dependencies appear as resolve inputs in a class or function header. For example, Worker(resolve Logger logger) receives the configured logger without a caller supplying that argument. An ordinary Logger logger input must be passed by label. See a complete constructor-injection example.

main.aug shows which providers the application chooses. A class or function header shows which ones it needs. The compiler checks the binding graph before execution; a missing or cyclic dependency fails checking.

Follow a dependency ​

Run aug spec . and read main.aug.md. Follow its links to the greeting's explanation, then read greeting/export.aug.md to see the public surface. In VS Code, Ctrl-click from or the module path to open the source or export file. Use these links to trace dependencies in a larger project.

Keep exports narrow as a folder grows. Export implementations that callers need to construct or bind. Keep helpers private. The next chapter adds a mutable counter and its tests.

The world runs on language