I have a WPF application with Ninject as the DI container. I have added the below code in the App.xaml.cs:
public partial class App : Application
{
private IKernel container;
protected override void OnStartup(StartupEventArgs e)
{
ConfigureContainer();
base.OnStartup(e);
}
private void ConfigureContainer()
{
this.container = new StandardKernel();
this.container.Bind<IAccountTypeRepository>().To<AccountTypeRepository>();
this.container.Bind<IMainWindow>().To<MainWindow>();
var mainWindow = this.container.Get<IMainWindow>();
mainWindow.Show();
}
}
When I try to call the IAccountTypeRepository in the code behind of my UserControl it throws a null exception. Can you please help what is missing in my code. Thank you so much. I need to have it as a Property Injection.
public interface IAccountTypeRepository
{
void Update(SqlParameter[] param);
DataTable GetAll(SqlParameter[] param);
}
public class AccountTypeRepository : IAccountTypeRepository
{
public void Update(SqlParameter[] param)
{
var sqlRepository = new SqlRepository();
sqlRepository.ExecuteNonQuery("MyStoredProc", param);
}
public DataTable GetAll(SqlParameter[] param)
{
var sqlRepository = new SqlRepository();
return sqlRepository.ExecuteDataTable("MyStoredProc", param);
}
}
Error Encountered: