Skip to content

Commit 4ed1e16

Browse files
Merge pull request #75 from josephmancuso/develop
Service Container Support
2 parents e6896f8 + b6450ba commit 4ed1e16

39 files changed

+41
-1913
lines changed

app/http/controllers/WelcomeController.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ class WelcomeController(object):
88
def __init__(self):
99
pass
1010

11-
def show(self, request):
11+
def show(self):
1212
''' Show Welcome Template '''
1313
return view('welcome', {'app': application})

app/providers/UserModelProvider.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from masonite.provider import ServiceProvider
2+
from app.User import User
3+
4+
class UserModelProvider(ServiceProvider):
5+
''' Binds the User model into the Service Container '''
6+
7+
def register(self):
8+
self.app.bind('User', User)
9+
10+
def boot(self):
11+
pass

bootstrap/start.py

+24-7
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
from masonite.request import Request
1010
from masonite.routes import Route
1111
from masonite.storage import Storage
12-
from config import middleware
12+
from masonite.app import App
13+
from config import middleware, application
1314
from pydoc import locate
1415

1516

16-
1717
# Run once and only once the server is ran
1818
# This will not actually compile if the libsass module in not installed
1919
Storage().compile_sass()
@@ -23,6 +23,27 @@ def app(environ, start_response):
2323
os.environ.setdefault('REQUEST_METHOD', environ['REQUEST_METHOD'])
2424
os.environ.setdefault('URI_PATH', environ['PATH_INFO'])
2525

26+
# Instantiate the Service Container
27+
app = App()
28+
29+
# Instantiate the Request object.
30+
# This is the `request` object passed into controller methods
31+
request = Request(environ)
32+
33+
# Bind the Request object into the container
34+
app.bind('Request', request)
35+
36+
# Execute all the register methods in all containers
37+
for provider in application.PROVIDERS:
38+
locate(provider)().load_app(app).register()
39+
40+
# Execute all the boot methods in all containers
41+
for provider in application.PROVIDERS:
42+
app.resolve(locate(provider)().boot)
43+
44+
# Load the container into the request
45+
app.make('Request').load_app(app)
46+
2647
router = Route(environ)
2748

2849
if router.is_post():
@@ -37,10 +58,6 @@ def app(environ, start_response):
3758
import routes.web
3859
routes = routes.web.ROUTES
3960

40-
# Instantiate the Request object.
41-
# This is the `request` object passed into controller methods
42-
request = Request(environ)
43-
4461
# Check all http routes
4562
for route in routes:
4663
# Compiles the given route to regex
@@ -88,7 +105,7 @@ def app(environ, start_response):
88105
# Get the data from the route. This data is typically the output
89106
# of the controller method
90107
if not request.redirect_url:
91-
data = router.get(route.route, route.output(request))
108+
data = router.get(route.route, app.resolve(route.output))
92109

93110
# Loads the request in so the middleware specified is able to use the
94111
# request object. This is after middleware and is ran after the request

config/application.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
|
3838
'''
3939

40-
KEY = os.environ.get('key')
40+
KEY = os.environ.get('KEY')
4141

4242
'''
4343
|--------------------------------------------------------------------------
@@ -64,7 +64,9 @@
6464
|
6565
'''
6666

67-
PROVIDERS = []
67+
PROVIDERS = [
68+
'app.providers.UserModelProvider.UserModelProvider'
69+
]
6870

6971
'''
7072
|--------------------------------------------------------------------------

docs/1.-Installation.md

-41
This file was deleted.

docs/1.1-Configuration.md

-23
This file was deleted.

docs/1.2-Directory-Structure.md

-110
This file was deleted.

docs/1.3-Deployment.md

-41
This file was deleted.

0 commit comments

Comments
 (0)