我正在使用Web应用程序,我有一个具有实现Interface的所有业务逻辑的类。我试图在startup.cs中引用接口和类,并尝试在Controller中初始化。我的业务逻辑类是这样的:
public class User_MasterDataAccesss: IUserMasterRepository
{
.... business logic
public int validate(string name)
{
...... doing something
}
}
我有一个接口,它有像这个
这样的验证功能的定义public interface IUserMasterRepository
{
int validate(string name);
}
我正在尝试在startup.cs中绑定接口,如此
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
// services.AddMvc();
// Add application services.
services.AddSingleton<IUserMasterRepository, User_MasterDataAccesss>();
}
}
我试图在控制器中初始化接口,如此
public class AuthenticationController : Controller
{
private IUserMasterRepository UserMasterRepository;
public AuthenticationController() { }
public AuthenticationController(IUserMasterRepository userMasterRepository)
{
this.UserMasterRepository = userMasterRepository;
}
......... action result actions which is using the UserMasterRepository
}
我的问题如下:
UserMasterRepository
为空。services.AddMvc();
在startup.cs中不存在我怎样才能做到这一点?哪里错了?