-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Local providers #30
Comments
I am also in favor of this feature, but with a few more restrictions regarding the quantity, precedence and relationship between internal orphans and provider instances, which allows us to use Impact of provider instances on the overall Proof resolutionI hope we agree that the overall assumption of provider instances is that they obey a subset of rules that Compatibility and compiler integrationWe could add a compiler flag, which overrules an internal orphan when an Proof resolution - Achieving package-level coherenceI imagine this behavior for proof resolution with provider instances - I am leaving out use cases of public instances since internal orphans and providers overrule them. package-level coherence specifically canceling out cases like below: package com.mypackage
class MyTest {
@Test
`some viewmodel test 1`() {
@Provider
val engine = MockEngine()
// ...
}
@Test
`some viewmodel test 2`() {
@Provider
val engine = MockEngine()
// ...
}
} where we would have to analyze both the package and the scope for coherence since we expect this to fail: package com.mypackage
class MyTest {
@Test
`some viewmodel test 1`() {
@Provider
val engine = MockEngine()
@Provider
val otherEngine = MockEngine()
// ...
}
} The first proposal is package scoped resolution of provider instances: package com.mypackage
// Environment: an internal orphan exists in this project (whether in main or test) - in this case there is no behavior change
// wether an internal orphan exists in main or test since there can only exist one internal orphan per project, and in the case that // it lives in test it changes the resolution in the test directory but not in main (main does not have the scope of descriptors in test)
class MyTest {
@Provider
val engine = MockEngine()
@Test
`some viewmodel test`() {
// ... the proof resolution picks `engine`
}
} It fails in cases where in the same package multiple If no provider instances is found in the same package directory, the existing proof resolution resolves the instance. In cases where in Please add any feedback! |
If I understood you correctly, we must not allow having multiple providers with the same parent. // This is used in all places except `SomeClass` and `SomeInnerClass`
@Provider internal fun foo(): Bar
class SomeClass {
// This is used inside `SomeClass` except `SomeInnerClass`
@Provider internal fun foo2(): Bar
inner class SomeInnerClass {
// This is used inside `SomeInnerClass`
@Provider fun foo3(): Bar
}
} |
That example is one that I am excluding out. This will fail since there are multiple Providers in the same package. I can also jump on a call if you have questions. The idea is to separate different Providers into their respective packages. so for a given Type
Both of these can coexist and only influence the provider coherence and discovery of the instance based on their package. That is the base idea. |
This feature is to allow providing proofs with different parents, so instead of getting an ambiguous proof error, we get the closest one.
It is totally oriented to testing, but it can/could be used outside of tests if needed.
Android common architecture example.
It is usual to have this layers:
Generally, one or more datasources are passed via repositories constructor implementation. At same time, one or repositories are passed via constructor to the use cases. Finally the ViewModel receives via constructor one or more use cases and the ViewModel is injected into the UI.
As you can see, technically you can create an integration test (understanding integration tests as a test that tests multiple components) for ViewModels manually by passing all instances via the constructor.
That process can be tedious and in those kinds of tests is in which a DI framework can shine.
If I want to test my ViewModel, in a lot of applications I only want to change the remote by using a mock web server or a mock engine if you are using Ktor, or in other words, providing multiple local JSON to be able to tests multiple paths, not only multiple happy paths, errors, and so on.
At the same time, those tests are written like unit tests, there is no emulator, so they run quickly, and testing the ViewModel implies you are testing the rest of the layers. In my opinion unit testing shines on libraries or edge cases, but in applications, the integration tests are the best way to get a robust product.
So I want to build tests that can have a complex graph of dependencies without maintaining manually that graph, so a simple test can be:
Our plugin should allow doing easily:
Or even, if possible
Probably there are use cases outside tests, I am not totally sure, but I would add a flag to block this usage to only tests, and enable it globally with that flag.
The text was updated successfully, but these errors were encountered: