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

Why use AddCustomRepository #109

Open
seeyouethan opened this issue Jul 25, 2019 · 3 comments
Open

Why use AddCustomRepository #109

seeyouethan opened this issue Jul 25, 2019 · 3 comments

Comments

@seeyouethan
Copy link

seeyouethan commented Jul 25, 2019

I have found that if I do not use "AddCustomRepository<Blog, CustomBlogRepository>()" in the Startup.cs ,it alse can run corrctly(it can alse get the right data in the mysql database)
so what's the meaning of use "AddCustomRepository<Blog, CustomBlogRepository>()" in the Startup.cs ?
Thanks.

@rigofunc
Copy link
Member

Yes, if you haven't any custom, will use the default impl

@panda-big
Copy link
Contributor

我发现如果我在Startup.cs中不使用“ AddCustomRepository <Blog,CustomBlogRepository>()”,它也可以正确运行(它也可以在mysql数据库中获取正确的数据),
所以使用的含义是什么?在Startup.cs中添加AddCustomRepository <Blog,CustomBlogRepository>()“?
谢谢。

因为是走的默认new 对象的方式

@tdav
Copy link

tdav commented Jan 26, 2020

//Insert AddCustomRepository
services
.AddDbContext(opt => opt.UseMySql(Configuration.GetConnectionString("DefaultConnection"),
ass => ass.MigrationsAssembly(typeof(RssDbContext).Assembly.FullName)))
.AddUnitOfWork()
.AddCustomRepository<tbFeedItem, FeedItemRepository>()
.AddCustomRepository<tbUser, UserRepository>();

//use custom repository
private readonly IUnitOfWork db;
private ILogger _logger;
public UsersController(IUnitOfWork _db, ILogger logger)
{
db = _db;
_logger = logger;
}
[AllowAnonymous]
[HttpPost("login")]
public IActionResult Authenticate([FromBody]viAuthenticateModel model)
{
var rpUser = db.GetRepository(true) as UserRepository;
var user = rpUser.Authenticate(model.Username, model.Password);
if (user == null)
return BadRequest(new { message = "Username or password is incorrect" });
return Ok(user);
}

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

4 participants