Repository: reagento/dishka

Issue:
Missing exception for provider when trying to use and return same type of dependency
## Description
You cannot create a dependency that relies on another dependency of the same type. This rule applies without exception, and if you try to do so, you will encounter a "RecursionError" instead of a library-level exception. This can make it difficult to understand the root cause of the issue.

## Code example
```python
class DBProvider(Provider):
    @provide(scope=Scope.REQUEST)
    async def get_transaction(self, db: DB) -> AsyncIterable[DB]:
        db.begin()
        yield db # RecursionError: maximum recursion depth exceeded
        db.commit()
```

Discussion:

Patch:
diff --git a/src/dishka/exceptions.py b/src/dishka/exceptions.py
index 1a05e98..fe8a810 100644
--- a/src/dishka/exceptions.py
+++ b/src/dishka/exceptions.py
@@ -30,7 +30,12 @@ class CycleDependenciesError(InvalidGraphError):
         self.path = path
 
     def __str__(self):
-        return "Cycle dependencies detected.\n" + _renderer.render(self.path)
+        if len(self.path) == 1:
+            hint = " Did you mean @decorate instead of @provide?"
+        else:
+            hint = ""
+        details = _renderer.render(self.path)
+        return f"Cycle dependencies detected.{hint}\n{details}"
 
 
 class ExitError(ExceptionGroup, DishkaError):
diff --git a/src/dishka/registry.py b/src/dishka/registry.py
index 4e3b09b..f1e9ca2 100644
--- a/src/dishka/registry.py
+++ b/src/dishka/registry.py
@@ -163,6 +163,11 @@ class GraphValidator:
             self, factory: Factory, registry_index: int,
     ):
         self.path[factory.provides] = factory
+        if (
+            factory.provides in factory.kw_dependencies.values() or
+            factory.provides in factory.dependencies
+        ):
+            raise CycleDependenciesError([factory])
         try:
             for dep in factory.dependencies:
                 # ignore TypeVar parameters


Test patch:
diff --git a/tests/unit/container/test_decorator.py b/tests/unit/container/test_decorator.py
index 3236f9b..b11cc7d 100644
--- a/tests/unit/container/test_decorator.py
+++ b/tests/unit/container/test_decorator.py
@@ -10,7 +10,7 @@ from dishka import (
     make_container,
     provide,
 )
-from dishka.exceptions import NoFactoryError
+from dishka.exceptions import CycleDependenciesError, NoFactoryError
 
 
 class A:
@@ -149,3 +149,19 @@ def test_missing_factory():
     with pytest.raises(NoFactoryError) as e:
         make_container(MyProvider())
     assert e.value.requested == DependencyKey(int, component=DEFAULT_COMPONENT)
+
+
+def test_expected_decorator():
+    class MyProvider(Provider):
+        scope = Scope.REQUEST
+
+        @provide(scope=Scope.APP)
+        def bar(self) -> A:
+            return A()
+
+        @provide
+        def foo(self, a: A) -> A:
+            return a
+
+    with pytest.raises(CycleDependenciesError):
+        make_container(MyProvider())