小编Cyr*_*and的帖子

如何获取 dotnet core 3 的路由属性?

我已将 dotnet core 2.2 升级到 3.preview 7。
因此之后,我无法获取自定义属性。
context.Resource在版本 2.2 中是类型 of AuthorizationFilterContext,但在版本 3 中是类型 of Microsoft.AspNetCore.Http.Endpoint

现在我无法从端点获取属性。

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace Gamma.Core.Security
{
    public abstract class AttributeAuthorizationHandler<TRequirement,     TAttribute>
    : AuthorizationHandler<TRequirement> where TRequirement
    : IAuthorizationRequirement where TAttribute : Attribute
    {
        Microsoft.AspNetCore.Http.IHttpContextAccessor _httpContextAccessor = null;
        public AttributeAuthorizationHandler(Microsoft.AspNetCore.Http.IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, TRequirement requirement)
        {
            var attributes = new …
Run Code Online (Sandbox Code Playgroud)

c# authorization routedata .net-core .net-core-3.0

5
推荐指数
2
解决办法
3751
查看次数

如何在C#中将pdf文件转换为excel

我想" email addresses "从 PDF 文件中的表格中提取一些数据,例如 .. 并使用我提取的电子邮件地址向这些人发送电子邮件。

到目前为止我通过网络搜索发现的内容:

  1. 我必须将 PDF 文件转换为 Excel 才能轻松读取数据并根据需要使用它们。

  2. 我找到了一些免费的 dll,例如itextsharpPDFsharp

但我没有找到任何有助于在 C# 中执行此操作的代码片段。有什么解决办法吗?

c# pdf excel itext

4
推荐指数
1
解决办法
4万
查看次数

在具有不同 timefmt 的 gnuplot 中绘制两个文件

我需要使用 gnuplot 在同一个图中绘制两个数据文件。第一个数据文件是这样的:

2015-02-10 10.1
2015-02-15 12.1
2015-02-20 16.1
2015-02-25 14.1
...
Run Code Online (Sandbox Code Playgroud)

第二个数据文件就像

2015-02-10-10:00 12.5
2015-02-10-15:00 21.4
2015-02-15-12:30 08.3
2015-02-15-22:00 09.3
2015-02-20-08:15 12.8
2015-02-20-17:32 16.7
2015-02-25-07:20 14.0
2015-02-25-21:39 14.5
..
Run Code Online (Sandbox Code Playgroud)

要解析第一个数据文件,timefmt应该设置为"%Y-%m-%d",对于第二个文件,应该设置为"%Y-%m-%d-%H:%M". 但是,由于两个数据文件应该一起绘制,我该如何timefmt正确定义?

gnuplot datetime-format

4
推荐指数
1
解决办法
402
查看次数

Autofac - 在构建之前解决

使用Unity可以在构建容器之前解析依赖关系.这也适用于Autofac吗?下面的代码演示了我的场景 - 我需要解决这个问题ICacheRepository,以便"新手"单身CacheHelper.

在Unity中,简单地用container.Resolve<ICacheRepository>()???代替.Autofac怎么样?

var builder = new ContainerBuilder();
builder.RegisterType<CacheRepository>().As<ICacheRepository>();
var cacheHelper = new CacheHelper(???);
builder.RegisterInstance(cacheHelper).As<CacheHelper>();
Run Code Online (Sandbox Code Playgroud)

哪个CacheHelper类具有构造函数依赖性CacheRepository.

public class CacheHelper
{
    private readonly ICacheRepository _repository;

    public CacheHelper(ICacheRepository repository)
    {
        _repository = repository;
    }
} 
Run Code Online (Sandbox Code Playgroud)

c# autofac

4
推荐指数
1
解决办法
2463
查看次数

如何使用工厂解析使用Autofac的界面

我希望得到如下服务

public SomeService(IMongoDatabase mongoDatabase) {
    DB = mongoDatabase;
}
Run Code Online (Sandbox Code Playgroud)

我想使用工厂来解决IMongoDatabase,只是为了封装IConfiguration用法

public static IMongoDatabase GetMongoDatabase(IConfiguration config)
{
    var connectionString = config.Get("SomeConnectionString");
    // MongoClient handles connection pooling internally
    var client = new MongoClient(connectionString); 
    var db = client.GetDatabase(config.Get("SomeDbName"));

    return db;
}
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚如何处理注册,以便MongoDbFactory.GetMongoDatabase在任何类需要时调用IMongoDatabase.IConfiguration将被注册.

我真的很想在我的服务中使用一个IMongoDatabase而不是一个Func<IConfiguration, IMongoDatabase>.后者似乎过于迟钝,要求消费者实施我应该能够为他们实施的步骤.

c# factory autofac

4
推荐指数
1
解决办法
1633
查看次数

Autofac 模块应该注册自己的依赖模块吗?

考虑我有一个使用三个库 lib1、lib2 和 lib3 的应用程序。在每个库中,我都实现了一个Module注册在该库中实现的依赖项。

其中一些实现有自己的依赖项,例如,lib2 和 lib3 可能都需要 lib1 中存在的一些实现。

我的问题是,我是否让 lib2 和 lib3 中的模块在 lib1 中注册模块作为其Load实现的一部分?如果我的应用程序注册了 lib2 和 lib3 的模块,这是否会注册该模块两次?

或者我是否避免让一个模块注册另一个模块,将它留给应用程序,但缺点是启动时可能会丢失某些注册?

c# autofac autofac-module

4
推荐指数
2
解决办法
1191
查看次数

无法使用autofac注册结构实例

我刚开始从Unity迁移到Autofac,我在尝试注册实例时遇到了问题.

public static void Register(ContainerBuilder containerBuilder,
                            CancellationToken shutDownCancellationToken)
{
    containerBuilder.RegisterType<CancellationToken>();
    containerBuilder.RegisterInstance(shutDownCancellationToken);
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

类型' CancellationToken'必须是引用类型才能T在泛型类型或方法中使用它作为参数' RegistrationExtensions.RegisterInstance<T>(ContainerBuilder, T)'

任何人都知道如何注册已经创建的结构实例?

c# dependency-injection autofac

4
推荐指数
1
解决办法
703
查看次数

Autofac - DelegatingHandler(HttpMessageHandler)注册

我有一个DelegatingHandler我需要注册的类库中的自定义Autofac.webapi主机解析它对运行时的依赖性,因此主机没有对此库的引用.

public class LocalizationHandler : DelegatingHandler
{
    protected override async Task<HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken cancellationToken )
    {}
}
Run Code Online (Sandbox Code Playgroud)

在我的Autofac初始化程序类中,我尝试过以下方法:

protected override void Load( ContainerBuilder builder )
{
     builder.RegisterType<LocalizationHandler>();
     builder.Register(c => new LocalizationHandler());
}
Run Code Online (Sandbox Code Playgroud)

在主机中注册此类处理程序的常规方法是:

public static void Register(HttpConfiguration httpConfiguration)
{        
    httpConfiguration.MapHttpAttributeRoutes();          
    httpConfiguration.MessageHandlers.Add(new LocalizationHandler());
}
Run Code Online (Sandbox Code Playgroud)

但是我没有访问这里的主机项目.任何想法如何注入处理程序ContainerBuilder

c# ioc-container autofac asp.net-web-api asp.net-web-api2

3
推荐指数
1
解决办法
3166
查看次数

如何使用C#从IIS获取当前的Worker Request列表?

我正在编写RESTful Web服务状态页面的代码.我想知道是否有将IIS的当前请求转移到C#中.

我正在使用IIS 7.0,我想要的信息

IIS>工作程序> ASP.NET v4.0 >请求

在此输入图像描述

c# iis iis-7 request worker

3
推荐指数
1
解决办法
1631
查看次数

使用 Autofac 注册通用接口和类

我当前的 Autofac 配置正在努力解析 WebApi 中的 ApiController。

我遇到困难的是,我尝试使用通用构造函数参数创建一个“BaseApiController”,但出现异常:

使用构造函数查找器“Autofac.Core.Activators.Reflection.DefaultConstructorFinder”找不到类型“Service`1[WorldRegion]”上的构造函数。

这是代码结构:

public interface IEntityKey { }
public class WorldRegion : IEntityKey { }
public interface IRepository<T> where T : IEntityKey { }
public interface IService<T> where T : IEntityKey { }
public abstract class Service<T> : IService<T> where T : IEntityKey { }
public interface IWorldRegionService : IService<WorldRegion> { }
public class WorldRegionService : Service<WorldRegion>, IWorldRegionService
{
    private readonly IRepository<WorldRegion> _repository;
}
Run Code Online (Sandbox Code Playgroud)

工作 API 控制器:

public class WorldRegionsController : BaseApiController
{
    private …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection autofac asp.net-web-api

3
推荐指数
1
解决办法
8411
查看次数