Closed wax911 closed 3 years ago
You can check the last rc-3, with proposal of KoinScopeComponent
design and new delegate solutions.
Thank you @arnaudgiuliani I have actually been using both KoinScopeComponent
and ComponentActivityExt
with activityScope()
and fragmentScope
in rc-3
which has indeed improved the ease of maintaining of KoinScopeComponent
significantly
great :)
@wax911 Do you have an example of usages this delegate? Thanks
Hi @egorikftp I used to, but since rc-3
introduced activityScope
and fragmentScope
I have long since moved from this approach, as I had pointed out earlier in the issue, the main limitation with the delegate approach is that if you plan to scope anything it would have to be tied to the delegate class ScopeComponent
, anything that would try to access scope modules would result in a definition not found since the ScopeComponent
would be final
Instead I've been using the APIs mentioned by @arnaudgiuliani above that does an awesome job of abstracting away the creation of scope objects so you don't have to worry about keeping the implementation details up to date
Is your feature request related to a problem? Please describe. Firstly thank you for the awesome work so far, I love koin and have been using it for more than a year now :100:! Seeing how
scope
andlifecycleScope
have been deprecated in favour ofScopeActivity
,ScopeFragment
,ScopeService
which is a great change, however in most cases (I don't speak for everyone) most people tend to have a customactivity
,fragment
orservice
base classes either it be a framework in use or just an additional layer of abstraction.In such a case providing concrete abstractions of
activity
,fragment
orservice
may prove difficult in such a case were a person is already using another framework e.g.workflow
,mvi-core
,conductor
e.t.c I am aware thatKoinScopeComponent
is an interface which provides the flexibility for the developer to implement and mirror theScope*
components, but I believe it maybe a nice addition to offer these scope components through delegation.Describe the solution you'd like I have created the following structures to demonstrate the use-case:
Sample implementation of
KoinScopeComponent
Function for delegation providing
KoinScope
Implementing on android service class
Implementing on android fragment/activity class e.t.c
Optional extension functions for resolving scope modules
Describe alternatives you've considered Prior to the use-case above I was implementing
KoinScopeComponent
directly and copying the contents ofScopeActivity
,ScopeFragment
,ScopeService
e.t.c but I worried that I may miss future changes/improvements that might be added to theScope*
components. The obvious limitation of the provided examples is the inability to provide thesource
toKoinScopeComponent.createScope(scopeID: ScopeID, scopeName: Qualifier, source: Any? = null)
asthis
inKoinScope.scope
would refer to the context ofKoinScope
Target Koin project
koin-androidx-scope
Conclusion I would like to know what you think about this and possibly shed some light over potential shortcomings. Thanks again :smiley: