Make middleware function public

Instead of passing in a function to plugin.init(),
just move the middleware registering function to a public API.

Not sure why I didn't do that in the first place, it's a lot more
consistent with the rest of the functionality (addBuild,
consumeBuild, ...).