Skip to content

Commit

Permalink
Merge pull request #43 from dotkernel/issue-39
Browse files Browse the repository at this point in the history
Updated 'create book module' tutorial to support dependency injection
  • Loading branch information
arhimede authored Jun 22, 2024
2 parents 37824bf + 36f53b9 commit a414847
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions docs/book/v5/tutorials/create-book-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ use Api\App\Helper\PaginationHelper;
use Api\Book\Collection\BookCollection;
use Api\Book\Entity\Book;
use Doctrine\ORM\EntityRepository;
use Dot\AnnotatedServices\Annotation\Entity;
use Dot\DependencyInjection\Attribute\Entity;

/**
* @Entity(name="Api\Book\Entity\Book")
* @extends EntityRepository<object>
*/
#[Entity(name: Book::class)]
class BookRepository extends EntityRepository
{
public function saveBook(Book $book): Book
Expand Down Expand Up @@ -204,16 +204,12 @@ namespace Api\Book\Service;

use Api\Book\Entity\Book;
use Api\Book\Repository\BookRepository;
use Dot\AnnotatedServices\Annotation\Inject;
use Dot\DependencyInjection\Attribute\Inject;
use DateTimeImmutable;

class BookService implements BookServiceInterface
{
/**
* @Inject({
* BookRepository::class,
* })
*/
#[Inject(BookRepository::class)]
public function __construct(protected BookRepository $bookRepository)
{
}
Expand Down Expand Up @@ -265,8 +261,8 @@ use Api\Book\Handler\BookHandler;
use Api\Book\Repository\BookRepository;
use Api\Book\Service\BookService;
use Api\Book\Service\BookServiceInterface;
use Dot\AnnotatedServices\Factory\AnnotatedRepositoryFactory;
use Dot\AnnotatedServices\Factory\AnnotatedServiceFactory;
use Dot\DependencyInjection\Factory\AttributedRepositoryFactory;
use Dot\DependencyInjection\Factory\AttributedServiceFactory;
use Mezzio\Hal\Metadata\MetadataMap;
use Api\App\ConfigProvider as AppConfigProvider;

Expand All @@ -284,9 +280,9 @@ class ConfigProvider
{
return [
'factories' => [
BookHandler::class => AnnotatedServiceFactory::class,
BookService::class => AnnotatedServiceFactory::class,
BookRepository::class => AnnotatedRepositoryFactory::class,
BookHandler::class => AttributedServiceFactory::class,
BookService::class => AttributedServiceFactory::class,
BookRepository::class => AttributedRepositoryFactory::class,
],
'aliases' => [
BookServiceInterface::class => BookService::class,
Expand Down Expand Up @@ -487,19 +483,17 @@ use Mezzio\Hal\ResourceGenerator;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Dot\AnnotatedServices\Annotation\Inject;
use Dot\DependencyInjection\Attribute\Inject;

class BookHandler implements RequestHandlerInterface
{
use ResponseTrait;

/**
* @Inject({
* HalResponseFactory::class,
* ResourceGenerator::class,
* BookServiceInterface::class
* })
*/
use HandlerTrait;

#[Inject(
HalResponseFactory::class,
ResourceGenerator::class,
BookServiceInterface::class
)]
public function __construct(
protected HalResponseFactory $responseFactory,
protected ResourceGenerator $resourceGenerator,
Expand Down

0 comments on commit a414847

Please sign in to comment.