Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service.Init()和model.Init()初始化位置问题 #103

Open
beancookie opened this issue Aug 10, 2020 · 0 comments
Open

service.Init()和model.Init()初始化位置问题 #103

beancookie opened this issue Aug 10, 2020 · 0 comments

Comments

@beancookie
Copy link

Your question

demo项目中如果在启动时将service.Init()放置在model.Init()代码之前,则启动时不会报错,但是调用gorm时则会抛出异常

Your scenes

应用能否正确初始化不应该依赖于代码位置

Your advice

在Repository工厂方法中加入gorm的空值判断用于提示开发者
func NewMysqlImpl(gh *gorm.DB) sys_user.Repository {
if nil == gh {
panic("model Init need before service Init")
}
return &mysqlImpl{
gh: gh,
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant