blob: ed4eed078ba958f9029d916067dd5dc92f010d22 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
require 'product'
require 'user'
class BootstrapContainer
def initialize(container = Spank::Container.new)
@container = container
end
def run
@container.register(:command_registry) { Booty::RouteRegistry.new }.as_singleton
@container.register(:front_controller) { @container.build(Booty::FrontController) }
@container.register(:view_engine) do
Booty::ViewEngine.new(:root_path => 'lib/commands', :master => 'master')
end
@container.register(:products_repository) do
Repository.new(:products, @container.resolve(:database_gateway), DataMapper.new(Product))
end
@container.register(:users_repository) do
Repository.new(:users, @container.resolve(:database_gateway), DataMapper.new(User))
end
@container.register(:database_gateway) do
@container.build(DatabaseGateway)
end
@container.register(:database_connection_factory) do
DatabaseConnectionFactory.new(@container.resolve(:database_configuration), @container.resolve(:database_connection_provider))
end
@container.register(:database_configuration) do
DatabaseConfiguration.new
end
@container.register(:database_connection_provider) do
SequelConnectionProvider.new
end
@container.register(:unit_of_work_interceptor) do
@container.build(UnitOfWorkInterceptor)
end
@container.register(:unit_of_work_factory) do
@container.build(UnitOfWorkFactory)
end
@container.register(:context) do
#this should be scoped to each request
SimpleContext.new
end.as_singleton
@container.register(:session_factory) do
@container.build(SessionFactory)
end
@container.register(:key) do
Key.new("database.session")
end
@container.register(:current_user_interceptor) do
@container.build(CurrentUserInterceptor)
end
Spank::IOC.bind_to(@container)
end
end
|