func NewRegistry() Registry {
	return Registry{
		Connection: func(reg Registry) *db.Db {
			return db.NewDb()
		},
		NewsModel: func(reg Registry) news.NewsRepository {
			return news.NewNewsRepository(reg.GetConnection())
		},
	}
}
Beispiel #2
0
func (this *NewsTableMigrationScript) GetExecutionContext() *lib.ExecutionContext {
	execContext := lib.NewExecutionContext()
	execContext.AddQueryToApply(lib.NewSimpleSqlInstruction(CREATE_NEWS_TABLE_SQL))
	execContext.AddQueryToRollback(lib.NewSimpleSqlInstruction(DROP_NEWS_TABLE_SQL))
	callback := func() error {
		newsRepo := news.NewNewsRepository(this.conn)
		newsEntity := news.News{
			Title:    "Some news",
			Text:     "Some text",
			AuthorId: 1}
		newsRepo.CreateNews(newsEntity)
		return nil
	}
	execContext.SuccessCallback = callback

	return execContext
}
Beispiel #3
0
func (dc DependencyContainer) CreateNewsModel() *news.NewsRepository {
	return news.NewNewsRepository(dc.GetConnection())
}