Skip to content

Instantly share code, notes, and snippets.

@brendensoares
Created August 17, 2018 01:13
Show Gist options
  • Save brendensoares/515c023acecc120f480d06c181e6e71a to your computer and use it in GitHub Desktop.
Save brendensoares/515c023acecc120f480d06c181e6e71a to your computer and use it in GitHub Desktop.
Revel Dependency Container
package app
import ("...")
var Domain DomainDependencyContainer
type DomainDependencyContainer struct {
AuthService services.AuthenticationService
UsersRepo UsersRepository
UsersFactory *users.Factory
OrdersRepo OrdersRepository
OrdersFactory *orders.Factory
ProductsRepo ProductsRepository
ProductsFactory *products.Factory
PromotionsRepo PromotionsRepository
PromotionsFactory *promotions.Factory
PaymentMethodsRepo PaymentMethodsRepository
PaymentMethodsFactory *paymentmethods.Factory
AddressesRepo AddressesRepository
}
func InitDomainLayer() {
revel.AppLog.Info("InitDomainLayer...")
Domain.UsersRepo = NewUsersRepo(rootApp.Mongo, Domain.UsersFactory)
Domain.OrdersRepo = NewOrdersRepo(rootApp.Mongo)
Domain.ProductsRepo = NewProductsRepo(rootApp.Mongo)
Domain.PromotionsRepo = NewPromotionsRepo(rootApp.Mongo)
Domain.PaymentMethodsRepo = NewPaymentMethodsRepo(rootApp.Mongo)
Domain.AddressesRepo = NewAddressesRepo(rootApp.Mongo)
Domain.UsersFactory = users.NewFactory(Domain.UsersRepo) // TODO: instead of passing the repo in, we should just require calling code to check the constraints...or should we? (factory knows the business rules for creating users)
Domain.OrdersFactory = orders.NewFactory(Domain.OrdersRepo)
Domain.ProductsFactory = products.NewFactory(Domain.ProductsRepo)
Domain.PromotionsFactory = promotions.NewFactory(Domain.PromotionsRepo)
Domain.PaymentMethodsFactory = paymentmethods.NewFactory(Domain.PaymentMethodsRepo)
Domain.AddressesFactory = addresses.NewFactory(Domain.AddressesRepo)
// Services
Domain.AuthService = NewEmailPasswordAuthService(Domain.UsersRepo, Domain.UsersFactory)
revel.AppLog.Info("Done.")
}
func init() {
revel.OnAppStart(InitDomainLayer, 50)
}
@mrgiaquino
Copy link

Can you possibly share the unit test for this? For example, if you are mocking AuthService?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment