How do I have my app service use my new db context? It looks like it wants an IRepository which points to the "default" context. Do I need to make a new AsyncCRUDServiceMyCustomDBContext and override the IRepository in there with my new one?
3 Answer(s)
-
0
I ended up getting it to work, but I now want to Implement a GenericAppService. But its throwing this error:
Castle.MicroKernel.Handlers.HandlerException occurred HResult=0x80131500 Message=Can't create component 'MMC.Platform.Web.Areas.App.Controllers.RPIListenerQueueController' as it has dependencies to be satisfied.
'MMC.Platform.Web.Areas.App.Controllers.RPIListenerQueueController' is waiting for the following dependencies:
- Service 'MMC.Platform.Generic.GenericAppService`3[[MMC.Platform.DMPModels.RpilistenerQueue, MMC.Platform.Core, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null],[MMC.Platform.DMPModels.RpilistenerQueue, MMC.Platform.Core, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null],[System.Int16, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' which was not registered.
Source=
public class GenericAppService<TEntity, TEntityDTO, TPrimaryKeyType> : AsyncCrudAppService<TEntity, TEntityDTO, TPrimaryKeyType, TEntityDTO, TEntityDTO, TEntityDTO, TEntityDTO, TEntityDTO>, IGenericAppService<TEntityDTO, TPrimaryKeyType> where TEntity : class, IEntity<TPrimaryKeyType> where TEntityDTO : IEntityDto<TPrimaryKeyType> { public GenericAppService(IRepository<TEntity, TPrimaryKeyType> repository) : base(repository) { } public IQueryable GetAllQueryable() { return Repository.GetAll(); } }
public interface IGenericAppService<TEntity, TPrimaryKeyType> : IAsyncCrudAppService<TEntity, TPrimaryKeyType, TEntity, TEntity, TEntity, TEntity, TEntity> where TEntity : IEntityDto<TPrimaryKeyType> { IQueryable GetAllQueryable(); }
public abstract class TelerikCRUDPlatformControllerBase<TEntity, TEntityDTO, TPrimaryKeyType> : PlatformControllerBase where TEntity : AuditBase<TPrimaryKeyType> where TEntityDTO : IEntityDto<TPrimaryKeyType> { private readonly GenericAppService<TEntity, TEntityDTO, TPrimaryKeyType> _appService; private string _deletePermission; private string _createPermission; private string _editPermission; private string _readPermission; protected TelerikCRUDPlatformControllerBase(GenericAppService<TEntity, TEntityDTO, TPrimaryKeyType> appService) { _appService = appService; } public virtual ActionResult Index() { return View(); } public virtual JsonResult Read([DataSourceRequest] DataSourceRequest request) { if (!PermissionChecker.IsGranted(_readPermission)) { throw new AbpAuthorizationException("You are not authorized to view/read!"); //ToDo: Create Localization } return Json(_appService.GetAllQueryable().ToDataSourceResult(request)); } [HttpPost] [DontWrapResult] public virtual async Task<ActionResult> Create([DataSourceRequest] DataSourceRequest request, TEntityDTO entity) { if (!PermissionChecker.IsGranted(_createPermission)) { throw new AbpAuthorizationException("You are not authorized to create!"); //ToDo: Create Localization } if (ModelState.IsValidWithNoAuditFieldsSet()) await _appService.Create(entity); return Json(new[] {entity}.ToDataSourceResult(request, ModelState)); } [HttpPost] [DontWrapResult] public virtual async Task<ActionResult> Update([DataSourceRequest] DataSourceRequest request, TEntityDTO entity) { if (!PermissionChecker.IsGranted(_editPermission)) { throw new AbpAuthorizationException("You are not authorized to edit!"); //ToDo: Create Localization } if (ModelState.IsValidWithNoAuditFieldsSet()) await _appService.Update(entity); return Json(new[] {entity}.ToDataSourceResult(request, ModelState)); } [HttpPost] [DontWrapResult] public virtual async Task<ActionResult> Destroy([DataSourceRequest] DataSourceRequest request, TEntityDTO entity) { if (!PermissionChecker.IsGranted(_deletePermission)) { throw new AbpAuthorizationException("You are not authorized to delete!"); //ToDo: Create Localization } await _appService.Delete(entity); return Json(new[] {entity}.ToDataSourceResult(request, ModelState)); } [HttpPost] public ActionResult Telerik_Export(string contentType, string base64, string fileName) { var fileContents = Convert.FromBase64String(base64); return File(fileContents, contentType, fileName); } }
Controller works if I make a normal AppService and derive from the CrudAsync
public class RPIListenerQueueController : TelerikCRUDPlatformControllerBase<RpilistenerQueue, RpilistenerQueue, short> { //private IRPIListenerQueueAppService _appService; private string _deletePermission; private string _createPermission; private string _editPermission; private string _readPermission; //public RPIListenerQueueController(IRPIListenerQueueAppService appService) //{ // _appService = appService; //} //public virtual ActionResult Index() //{ // return View(); //} //public virtual JsonResult Read([DataSourceRequest] DataSourceRequest request) //{ // if (!PermissionChecker.IsGranted(_readPermission)) // { // throw new AbpAuthorizationException("You are not authorized to view/read!"); //ToDo: Create Localization // } // return Json(_appService.GetAllQueryable().ToDataSourceResult(request)); //} //[HttpPost] //[DontWrapResult] //public virtual async Task<ActionResult> Create([DataSourceRequest] DataSourceRequest request, RpilistenerQueue entity) //{ // if (!PermissionChecker.IsGranted(_createPermission)) // { // throw new AbpAuthorizationException("You are not authorized to create!"); //ToDo: Create Localization // } // if (ModelState.IsValidWithNoAuditFieldsSet()) // await _appService.Create(entity); // return Json(new[] { entity }.ToDataSourceResult(request, ModelState)); //} //[HttpPost] //[DontWrapResult] //public virtual async Task<ActionResult> Update([DataSourceRequest] DataSourceRequest request, RpilistenerQueue entity) //{ // if (!PermissionChecker.IsGranted(_editPermission)) // { // throw new AbpAuthorizationException("You are not authorized to edit!"); //ToDo: Create Localization // } // if (ModelState.IsValidWithNoAuditFieldsSet()) // await _appService.Update(entity); // return Json(new[] { entity }.ToDataSourceResult(request, ModelState)); //} //[HttpPost] //[DontWrapResult] //public virtual async Task<ActionResult> Destroy([DataSourceRequest] DataSourceRequest request, RpilistenerQueue entity) //{ // if (!PermissionChecker.IsGranted(_deletePermission)) // { // throw new AbpAuthorizationException("You are not authorized to delete!"); //ToDo: Create Localization // } // await _appService.Delete(entity); // return Json(new[] { entity }.ToDataSourceResult(request, ModelState)); //} //[HttpPost] //public ActionResult Telerik_Export(string contentType, string base64, string fileName) //{ // var fileContents = Convert.FromBase64String(base64); // return File(fileContents, contentType, fileName); //} public RPIListenerQueueController(GenericAppService<RpilistenerQueue, RpilistenerQueue, short> appService) : base(appService) { } }
-
0
Bump
-
0
Hi,
Have you added RpilistenerQueue to your dbContext ?