I'm new with this kind of technology. Been trying to resolve this issue for days now, tried all possible answers here in stack but still can't get my issue fixed. When I run my code on my local machine it is working, but when I run in server (IIS) it is not, it's throwing an NullReference exception, so I'm creating logs all working until the section where it is calling the inject one.
[Inject]
public ICustomerManagementService CustomerManagementService { get; set; }
public CustomerDetailsResponse GetCustomerInformation(CustomerDetailsRequest _request)
{
CustomerDetailsResponse _response = new CustomerDetailsResponse(_request);
_response.ResponseDetails = new CustomerDetailsResponseDetails();
_response.ResponseDetails.ResultDetails = new List<CustomerDetails>();
try
{
if (!ModelState.IsValid)
{
throw new RequestValidationException(ModelState);
}
List<CustomerDetails> _data = CustomerManagementService.GetCustomerDetails(_request.RequestDetails, _request.RequestHeader.RequesterContext.RegionalCode);
_response.ResponseDetails.ResultDetails = _data;
if (_request.RequestDetails.Paging == true)
{
_response.ResponseDetails.Paging = new PagingParameter();
PagingParameter _paging = new PagingParameter();
_paging.PageSize = _request.RequestDetails.PagingParameter.PageSize;
_paging.PageNumber = _request.RequestDetails.PagingParameter.PageNumber;
_paging.TotalCount = _data.Count();
_paging.TotalPages = (int)Math.Ceiling(_paging.TotalCount / (double)_request.RequestDetails.PagingParameter.PageSize);
_paging.HasNext = _request.RequestDetails.PagingParameter.PageNumber < _paging.TotalCount ? true : false;
_paging.HasPrev = _request.RequestDetails.PagingParameter.PageNumber > 1 ? true : false;
_response.ResponseDetails.Paging = _paging;
}
return _response;
}
catch (Exception e)
{
AuditLogger.Error(String.Format("Reference-{1}-Exception during API process: {0} ", e, _request.RequestHeader.RequesterContext.RequestID));
CustomerDetailsResponse response = (CustomerDetailsResponse) new ExceptionHandler().GetExceptionResponse(_request, new CustomerDetailsResponse(_request), e);
response.ResponseHeader.ResponseStatus = ResponseCode.FAILMSG;
return response;
}
}
The list part from code above. I followed tutorials from Ninject,
this is my Ninject.Web.Common:
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
try
{
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
RegisterServices(kernel);
GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
return kernel;
}
catch
{
kernel.Dispose();
throw;
}
}
/// <summary>
/// Load your modules or register your services here!
/// </summary>
/// <param name="kernel">The kernel.</param>
private static void RegisterServices(IKernel kernel)
{
// Service - BL
kernel.Bind<ICustomerManagementService>().To<CustomerManagementService>();
// Repository
kernel.Bind<ICustomerRepository>().To<CustomerRepositoryService>();
}
I'm using Ninject 3.3.4, ASP.NET MVC 5, Ninject.Web.Common 3.3.0, Ninject.Web.Common.WebHost 3.3.0
All DLL's has been uploaded in the server, before one of the API is working on the server. But now all API in the service is not working. Please help! Really appreciate it.