Skip to content

Commit a414847

Browse files
authored
Merge pull request #43 from dotkernel/issue-39
Updated 'create book module' tutorial to support dependency injection
2 parents 37824bf + 36f53b9 commit a414847

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

docs/book/v5/tutorials/create-book-module.md

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ use Api\App\Helper\PaginationHelper;
157157
use Api\Book\Collection\BookCollection;
158158
use Api\Book\Entity\Book;
159159
use Doctrine\ORM\EntityRepository;
160-
use Dot\AnnotatedServices\Annotation\Entity;
160+
use Dot\DependencyInjection\Attribute\Entity;
161161

162162
/**
163-
* @Entity(name="Api\Book\Entity\Book")
164163
* @extends EntityRepository<object>
165164
*/
165+
#[Entity(name: Book::class)]
166166
class BookRepository extends EntityRepository
167167
{
168168
public function saveBook(Book $book): Book
@@ -204,16 +204,12 @@ namespace Api\Book\Service;
204204

205205
use Api\Book\Entity\Book;
206206
use Api\Book\Repository\BookRepository;
207-
use Dot\AnnotatedServices\Annotation\Inject;
207+
use Dot\DependencyInjection\Attribute\Inject;
208208
use DateTimeImmutable;
209209

210210
class BookService implements BookServiceInterface
211211
{
212-
/**
213-
* @Inject({
214-
* BookRepository::class,
215-
* })
216-
*/
212+
#[Inject(BookRepository::class)]
217213
public function __construct(protected BookRepository $bookRepository)
218214
{
219215
}
@@ -265,8 +261,8 @@ use Api\Book\Handler\BookHandler;
265261
use Api\Book\Repository\BookRepository;
266262
use Api\Book\Service\BookService;
267263
use Api\Book\Service\BookServiceInterface;
268-
use Dot\AnnotatedServices\Factory\AnnotatedRepositoryFactory;
269-
use Dot\AnnotatedServices\Factory\AnnotatedServiceFactory;
264+
use Dot\DependencyInjection\Factory\AttributedRepositoryFactory;
265+
use Dot\DependencyInjection\Factory\AttributedServiceFactory;
270266
use Mezzio\Hal\Metadata\MetadataMap;
271267
use Api\App\ConfigProvider as AppConfigProvider;
272268

@@ -284,9 +280,9 @@ class ConfigProvider
284280
{
285281
return [
286282
'factories' => [
287-
BookHandler::class => AnnotatedServiceFactory::class,
288-
BookService::class => AnnotatedServiceFactory::class,
289-
BookRepository::class => AnnotatedRepositoryFactory::class,
283+
BookHandler::class => AttributedServiceFactory::class,
284+
BookService::class => AttributedServiceFactory::class,
285+
BookRepository::class => AttributedRepositoryFactory::class,
290286
],
291287
'aliases' => [
292288
BookServiceInterface::class => BookService::class,
@@ -487,19 +483,17 @@ use Mezzio\Hal\ResourceGenerator;
487483
use Psr\Http\Message\ResponseInterface;
488484
use Psr\Http\Message\ServerRequestInterface;
489485
use Psr\Http\Server\RequestHandlerInterface;
490-
use Dot\AnnotatedServices\Annotation\Inject;
486+
use Dot\DependencyInjection\Attribute\Inject;
491487

492488
class BookHandler implements RequestHandlerInterface
493489
{
494-
use ResponseTrait;
495-
496-
/**
497-
* @Inject({
498-
* HalResponseFactory::class,
499-
* ResourceGenerator::class,
500-
* BookServiceInterface::class
501-
* })
502-
*/
490+
use HandlerTrait;
491+
492+
#[Inject(
493+
HalResponseFactory::class,
494+
ResourceGenerator::class,
495+
BookServiceInterface::class
496+
)]
503497
public function __construct(
504498
protected HalResponseFactory $responseFactory,
505499
protected ResourceGenerator $resourceGenerator,

0 commit comments

Comments
 (0)