Explore the possiblity to define schema and constunct object in Spring (DI framework) style
- Dominant language
- Kotlin
- Stars
- 1.1k
- Forks
- 83
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 30
Description
Motivation:
- Nice to have an ability to hide reading the schema and object construction from the user in DI style where all the data sources and its life-cycle is managed by DI framework
- Unified approach for Spring developers
We want to have something like
```
@DataSource(csvFile = "data.csv")
val df: DataFrame
```
it should be, for example RUNTIME-annotation
```
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.RUNTIME)
annotation class DataSource(val csvFile: String)
```
we need a DataFrame postprocessor in the style
```
@Component
class DataFramePostProcessor : BeanPostProcessor {
override fun postProcessBeforeInitialization(bean: Any, beanName: String): Any? {
bean::class.memberProperties.forEach { prop ->
val annotation = prop.findAnnotation()
if (annotation != null) {
val csvPath = annotation.csvFile
val dataFrame = DataFrame.readCSV(File(csvPath))
val field = bean.javaClass.getDeclaredField(prop.name)
field.isAccessible = true
field.set(bean, dataFrame)
}
}
return bean
}
}
```
The usage of the bean could be like below
```
@Component
class MyDataService {
@DataSource(csvFile = "data.csv")
lateinit var df: DataFrame
fun process() {
println(df.rowsCount())
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.