protected function middlewareFactory(string $middleware, array $parameters): object
	{
		// Merge middleware parameters

		$parameters = $this->mergeParameters($parameters, $middleware);

		// Create middleware instance

		$middleware = $this->container->get($middleware, $parameters);

		// Check if the middleware implements the expected interface

		if($this->expectedInterface !== null && ($middleware instanceof $this->expectedInterface) === false)
		{
			throw new OnionException(vsprintf('The Onion instance expects the middleware to be an instance of [ %s ].', [$this->expectedInterface]));
		}

		// Return middleware instance

		return $middleware;
	}