Skip to content

Instantly share code, notes, and snippets.

View sullivan-'s full-sized avatar

John Sullivan sullivan-

View GitHub Profile
import org.scalatest.mock.EasyMockSugar
trait RepositoryComponentMock
extends RepositoryComponent
with EasyMockSugar {
val projectRepository = mock[ProjectRepository]
val userRepository = mock[UserRepository]
}
trait ServiceComponentMock
trait ChartViewFactoryComponent {
val chartViewFactory: ChartViewFactory
trait ChartViewFactory {
def create(chart: Chart): ChartView
}
}
trait ChartViewFactoryComponentImpl extends ChartViewFactoryComponent {
self: HistogramViewFactoryComponent with ScatterPlotViewFactoryComponent =>
override val chartViewFactory: ChartViewFactory = new ChartViewFactoryImpl
trait ChartViewComponent
extends ChartViewFactoryComponent
trait ChartViewComponentImpl
extends ChartViewComponent
with ChartViewFactoryComponentImpl
with HistogramViewFactoryComponentImpl
with ScatterPlotViewFactoryComponentImpl
trait ViewComponent
@Component @Scope("prototype")
public class StatefulService {
// ...
}
@Component
public class ReferencingService {
// every referencing component will get its own instance of the service
@Autowired
trait StatefulServiceComponent {
def statefulService: StatefulService
trait StatefulService {
// ...
}
}
trait StatefulServiceComponentImpl extends StatefulServiceComponent {
override def statefulService: StatefulService = new StatefulServiceImpl
private class StatefulServiceImpl extends StatefulService {
trait ReferencingServiceComponent {
def referencingService: ReferencingService
trait ReferencingService {
// ...
}
}
trait ReferencingServiceComponentImpl extends ReferencingServiceComponent {
self: StatefulServiceComponent =>
abstract class MyApplication extends TopComponent {
def start = {
// ...
}
// ...
}
object MyApplication {
def main(args: Array[String]) =
(new MyApplication with TopComponentImpl).start
}
object MyApplication {
def main(args: Array[String]) = {
val app =
if (testMode)
(new MyApplication with TopComponentTestImpl)
else
(new MyApplication with TopComponentImpl)
app.start
}
}
trait TopComponent
extends RepositoryComponent
with ServiceComponent
object TopComponentImpl extends TopComponentImpl
trait TopComponentImpl
extends TopComponent
with RepositoryComponentImpl
with ServiceComponentImpl