激活 Castle.Proxies.AlertAppServiceProxy 时抛出异常

Kev*_*inL 3 abp

我正在尝试利用书籍和作者 abp 教程来构建示例应用程序。

在我的示例应用程序中,我有网站(而不是书籍)和警报(而不是作者)。

一切似乎都是对的。但是,一旦我加载 /alerts 页面,我就会收到以下错误。

寻找如何解决的方向......

我最接近的是这个链接:Abp.io 异常:激活 Castle.Proxies.ProcessesServiceProxy 时抛出异常

但是,我不确定该用户到底做了什么来解决他们的问题。

[14:56:47 INF] Authorization was successful.
[14:56:47 INF] Executing endpoint 'MyApp.Alerts.AlertAppService.GetListAsync (MyApp.Application)'
[14:56:47 INF] Route matched with {action = "GetList", controller = "Alert", area = "", page = ""}. Executing controller action with signature System.Threading.Tasks.Task`1[Volo.Abp.Application.Dtos.PagedResultDto`1[MyApp.Alerts.AlertDto]] GetListAsync(Volo.Abp.Application.Dtos.PagedAndSortedResultRequestDto) on controller MyApp.Alerts.AlertAppService (MyApp.Application).
[14:56:47 ERR] ---------- RemoteServiceErrorInfo ----------
{
  "code": null,
  "message": "An internal error occurred during your request!",
  "details": null,
  "data": {
    "ActivatorChain": "Castle.Proxies.AlertAppServiceProxy"
  },
  "validationErrors": null
}

[14:56:47 ERR] An exception was thrown while activating Castle.Proxies.AlertAppServiceProxy.
Autofac.Core.DependencyResolutionException: An exception was thrown while activating Castle.Proxies.AlertAppServiceProxy.
 ---> Autofac.Core.DependencyResolutionException: None of the constructors found with 'Volo.Abp.Autofac.AbpAutofacConstructorFinder' on type 'Castle.Proxies.AlertAppServiceProxy' can be invoked with the available services and parameters:
Cannot resolve parameter 'MyApp.Sites.ISiteRepository siteRepository' of constructor 'Void .ctor(Castle.DynamicProxy.IInterceptor[], Volo.Abp.Domain.Repositories.IRepository`2[MyApp.Alerts.Alert,System.Guid], MyApp.Sites.ISiteRepository)'.
   at Autofac.Core.Activators.Reflection.ReflectionActivator.GetAllBindings(ConstructorBinder[] availableConstructors, IComponentContext context, IEnumerable`1 parameters)
   at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
   at Autofac.Core.Activators.Reflection.ReflectionActivator.<ConfigurePipeline>b__11_0(ResolveRequestContext ctxt, Action`1 next)
   at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Builder.RegistrationBuilder`3.<>c__DisplayClass41_0.<PropertiesAutowired>b__0(ResolveRequestContext ctxt, Action`1 next)
   at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   --- End of inner exception stack trace ---
   at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Builder.RegistrationBuilder`3.<>c__DisplayClass35_0.<OnPreparing>b__0(ResolveRequestContext ctxt, Action`1 next)
   at Autofac.Core.Resolving.Middleware.CoreEventMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Middleware.SharingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Middleware.CircularDependencyDetectorMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, ResolveRequest request)
   at Autofac.Core.Resolving.ResolveOperation.ExecuteOperation(ResolveRequest request)
   at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
   at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
   at Microsoft.AspNetCore.Mvc.Controllers.ServiceBasedControllerActivator.Create(ControllerContext actionContext)
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)[14:56:47 ERR] ---------- Exception Data ----------
ActivatorChain = Castle.Proxies.AlertAppServiceProxy

[14:56:47 INF] Executing ObjectResult, writing value of type 'Volo.Abp.Http.RemoteServiceErrorResponse'.
[14:56:47 INF] Executed action MyApp.Alerts.AlertAppService.GetListAsync (MyApp.Application) in 4.1234ms
[14:56:47 INF] Executed endpoint 'MyApp.Alerts.AlertAppService.GetListAsync (MyApp.Application)'
Run Code Online (Sandbox Code Playgroud)

编辑:这是 MyApp.Domain/Sites/ 中的“ISiteRepository.cs”

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;

namespace MyApp.Sites
{
    public interface ISiteRepository : IRepository<Site, Guid>
    {
        Task<Site> FindByNameAsync(string company);

        Task<List<Site>> GetListAsync(
            int skipCount,
            int maxResultCount,
            string sorting,
            string filter = null
        );
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑2:ISiteRepository注册(我认为)-在“MyApp.Application/Alerts/AlertAppService.cs”中

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MyApp.Sites;
using MyApp.Permissions;
using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;

namespace MyApp.Alerts
{
    [Authorize(MyAppPermissions.Alerts.Default)]
    public class AlertAppService :
        CrudAppService<
            Alert, //The  Alert entity
            AlertDto, //Used to show  alerts
            Guid, //Primary key of the  alert entity
            PagedAndSortedResultRequestDto, //Used for paging/sorting
            CreateUpdateAlertDto>, //Used to create/update a  alert
        IAlertAppService //implement the IAlertAppService
    {
        private readonly ISiteRepository _siteRepository;

        public AlertAppService(
            IRepository<Alert, Guid> repository,
            ISiteRepository siteRepository)
            : base(repository)
        {
            _siteRepository = siteRepository;
            GetPolicyName = MyAppPermissions.Alerts.Default;
            GetListPolicyName = MyAppPermissions.Alerts.Default;
            CreatePolicyName = MyAppPermissions.Alerts.Create;
            UpdatePolicyName = MyAppPermissions.Alerts.Edit;
            DeletePolicyName = MyAppPermissions.Alerts.Delete;
        }


        public override async Task<AlertDto> GetAsync(Guid id)
        {
            //Get the IQueryable<Alert> from the repository
            var queryable = await Repository.GetQueryableAsync();

            //Prepare a query to join sites and alerts
            var query = from Alert in queryable
                        join site in _siteRepository on Alert.SiteId equals site.Id
                        where Alert.Id == id
                        select new { Alert, site };

            //Execute the query and get the Alert with site
            var queryResult = await AsyncExecuter.FirstOrDefaultAsync(query);
            if (queryResult == null)
            {
                throw new EntityNotFoundException(typeof(Alert), id);
            }

            var AlertDto = ObjectMapper.Map<Alert, AlertDto>(queryResult.Alert);
            AlertDto.SiteName = queryResult.site.Name;
            return AlertDto;
        }

        public override async Task<PagedResultDto<AlertDto>> GetListAsync(PagedAndSortedResultRequestDto input)
        {
            //Set a default sorting, if not provided
            if (input.Sorting.IsNullOrWhiteSpace())
            {
                input.Sorting = nameof(Alert.SiteName);
            }

            //Get the IQueryable<Book> from the repository
            var queryable = await Repository.GetQueryableAsync();

            //Prepare a query to join Alerts and sites
            var query = from Alert in queryable
                        join site in _siteRepository on Alert.SiteId equals site.Id
                        orderby input.Sorting //TODO: Can not sort like that!
                        select new { Alert, site };

            //Paging
            query = query
                .Skip(input.SkipCount)
                .Take(input.MaxResultCount);

            //Execute the query and get a list
            var queryResult = await AsyncExecuter.ToListAsync(query);

            //Convert the query result to a list of AlertDto objects
            var AlertDtos = queryResult.Select(x =>
            {
                var AlertDto = ObjectMapper.Map<Alert, AlertDto>(x.Alert);
                AlertDto.SiteName = x.site.Name;
                return AlertDto;
            }).ToList();

            //Get the total count with another query
            var totalCount = await Repository.GetCountAsync();

            return new PagedResultDto<AlertDto>(
                totalCount,
                AlertDtos
            );
        }

        public async Task<ListResultDto<SiteLookupDto>> GetSiteLookupAsync()
        {
            var sites = await _siteRepository.GetListAsync();

            return new ListResultDto<SiteLookupDto>(
                ObjectMapper.Map<List<Site>, List<SiteLookupDto>>(sites)
            );
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Sip*_*nya 5

如果未设置模型的 DBSet,也可能会发生此错误。

public DbSet<Alert> Alerts {get;set;}
Run Code Online (Sandbox Code Playgroud)