55from typing import TYPE_CHECKING , Optional , cast
66
77from litestar .constants import HTTP_RESPONSE_START
8+ from litestar .di import Provide
89from litestar .exceptions import ImproperlyConfiguredException
910from litestar .utils .dataclass import simple_asdict
1011from oracledb import create_pool_async as oracledb_create_pool
1516from litestar_oracledb .config ._common import (
1617 CONNECTION_SCOPE_KEY ,
1718 SESSION_TERMINUS_ASGI_EVENTS ,
18- GenericDatabaseConfig ,
19- GenericPoolConfig ,
19+ GenericOracleDatabaseConfig ,
20+ GenericOraclePoolConfig ,
2021)
2122
2223if TYPE_CHECKING :
@@ -120,15 +121,15 @@ async def handler(message: Message, scope: Scope) -> None:
120121
121122
122123@dataclass
123- class AsyncPoolConfig ( GenericPoolConfig [AsyncConnectionPool , AsyncConnection ]):
124+ class AsyncOraclePoolConfig ( GenericOraclePoolConfig [AsyncConnectionPool , AsyncConnection ]):
124125 """Async Oracle Pool Config"""
125126
126127
127128@dataclass
128- class AsyncDatabaseConfig ( GenericDatabaseConfig [AsyncConnectionPool , AsyncConnection ]):
129+ class AsyncOracleDatabaseConfig ( GenericOracleDatabaseConfig [AsyncConnectionPool , AsyncConnection ]):
129130 """Async Oracle database Configuration."""
130131
131- pool_config : AsyncPoolConfig | None = None
132+ pool_config : AsyncOraclePoolConfig | None = None
132133 """Oracle Pool configuration"""
133134
134135 def __post_init__ (self ) -> None :
@@ -168,6 +169,18 @@ def signature_namespace(self) -> dict[str, Any]:
168169 "AsyncConnectionPool" : AsyncConnectionPool ,
169170 }
170171
172+ @property
173+ def dependencies (self ) -> dict [str , Any ]:
174+ """Return the plugin's signature namespace.
175+
176+ Returns:
177+ A string keyed dict of names to be added to the namespace for signature forward reference resolution.
178+ """
179+ return {
180+ self .pool_dependency_key : Provide (self .provide_pool , sync_to_thread = False ),
181+ self .connection_dependency_key : Provide (self .provide_connection ),
182+ }
183+
171184 async def create_pool (self ) -> AsyncConnectionPool :
172185 """Return a pool. If none exists yet, create one.
173186
@@ -198,7 +211,7 @@ async def lifespan(
198211 try :
199212 yield
200213 finally :
201- await db_pool .close ()
214+ await db_pool .close (force = True )
202215
203216 async def provide_connection (
204217 self ,
@@ -218,7 +231,9 @@ async def provide_connection(
218231 "Optional[AsyncConnection]" ,
219232 get_scope_state (scope , self .connection_scope_key ),
220233 )
221- if connection is None :
234+ if connection is not None :
235+ yield connection
236+ else :
222237 pool = cast ("AsyncConnectionPool" , state .get (self .pool_app_state_key ))
223238
224239 async with pool .acquire () as connection :
0 commit comments