From 4297ab0b94fef9d4e2f55279f786fa7bc333d0ee Mon Sep 17 00:00:00 2001 From: Doctor Date: Fri, 16 Feb 2024 16:20:33 +0300 Subject: [PATCH] Remove examples (moved to docs) --- examples/fastapi.md | 38 ---------------------------------- examples/litestar.md | 33 ----------------------------- examples/strawberry-graphql.md | 38 ---------------------------------- 3 files changed, 109 deletions(-) delete mode 100644 examples/fastapi.md delete mode 100644 examples/litestar.md delete mode 100644 examples/strawberry-graphql.md diff --git a/examples/fastapi.md b/examples/fastapi.md deleted file mode 100644 index 2e0eaa9..0000000 --- a/examples/fastapi.md +++ /dev/null @@ -1,38 +0,0 @@ -```python -import contextlib -from collections.abc import AsyncIterator -from typing import Annotated - -import uvicorn -from fastapi import FastAPI - -import aioinject -from aioinject import Inject -from aioinject.ext.fastapi import AioInjectMiddleware, inject - -container = aioinject.Container() -container.register(aioinject.Object(42)) - - -@contextlib.asynccontextmanager -async def lifespan(_: FastAPI) -> AsyncIterator[None]: - async with container: - pass - - -def create_app() -> FastAPI: - app = FastAPI(lifespan=lifespan) - - @app.get("/") - @inject - async def root(number: Annotated[int, Inject]) -> int: - return number - - app.add_middleware(AioInjectMiddleware, container=container) - - return app - - -if __name__ == "__main__": - uvicorn.run("main:create_app", factory=True, reload=True) -``` diff --git a/examples/litestar.md b/examples/litestar.md deleted file mode 100644 index a3ada6a..0000000 --- a/examples/litestar.md +++ /dev/null @@ -1,33 +0,0 @@ -```python -from typing import Annotated - -import uvicorn -from litestar import Litestar, get - -import aioinject -from aioinject import Inject -from aioinject.ext.litestar import AioInjectPlugin, inject - -container = aioinject.Container() -container.register(aioinject.Object(42)) - - -@get("/") -@inject -async def function_route( - number: Annotated[int, Inject], -) -> int: - return number - - -def create_app() -> Litestar: - return Litestar( - [function_route], - plugins=[AioInjectPlugin(container=container)], - ) - - -if __name__ == "__main__": - uvicorn.run("main:create_app", factory=True, reload=True) - -``` diff --git a/examples/strawberry-graphql.md b/examples/strawberry-graphql.md deleted file mode 100644 index 68d945d..0000000 --- a/examples/strawberry-graphql.md +++ /dev/null @@ -1,38 +0,0 @@ -```python -from typing import Annotated - -import strawberry -import uvicorn -from strawberry import Schema -from strawberry.asgi import GraphQL - -import aioinject -from aioinject import Inject -from aioinject.ext.strawberry import AioInjectExtension, inject - -container = aioinject.Container() -container.register(aioinject.Object(42)) - - -@strawberry.type -class Query: - @strawberry.field - @inject - async def number(self, number: Annotated[int, Inject]) -> int: - return number - - -def create_app() -> GraphQL: - schema = Schema( - query=Query, - extensions=[ - AioInjectExtension(container=container), - ], - ) - return GraphQL(schema=schema) - - -if __name__ == "__main__": - uvicorn.run("main:create_app", factory=True, reload=True) - -```