我尝试使用带有Autofac的Autofac.Extras.Quartz库的石英。但是我的代码崩溃了,这很简单,但是它崩溃了:
using Autofac;
using Autofac.Extras.Quartz;
using Quartz;
using System;
namespace Test1_netCore
{
class Program
{
static void Main(string[] args)
{
var builder = new ContainerBuilder();
b
我在使用web api的autofac时遇到了问题。我有一个自定义的ExceptionFilterAttribute,它覆盖OnException来记录和处理任何可能发生的异常。ExceptionFilterAttribute应用于一个ApiController类。
过滤代码如下:
public class ExceptionFilterAttribute : ExceptionFilterAttribute, IAutofacExceptionFilter
{
private ILogger _logger;
public ExceptionFilterAttribute(
我现在正在学习.NetCore和Autofac,我对如何将位图模块转换为Autofac模块有疑问。
让我们看看一些代码:
模块:
using Ninject.Modules;
namespace v0.CrossCutting.Ninject.Domain.Data
{
using v0.Domain.Data.Model.Interfaces;
using v0.Domain.Data.Model.Classes;
public class Model : NinjectModule
{
public override void Load(
我试图开始使用中间件并为项目创建一个记录器,并认为autofac log4net 是一个很好的起点,因为该项目已经在使用autofac,但我无法这样做。我有以下课程:
using System;
using System.Linq;
using System.Reflection;
using Autofac;
using Autofac.Core;
using Autofac.Core.Registration;
using Autofac.Core.Resolving.Pipeline;
using log4net;
using Microsoft.VisualStudio.TestToo
我有一个简单的MVC应用程序,我试图在其中添加一个异常过滤器。为了做到这一点,我遵循了我认为适用于Autofac.WebApi2 NuGet包的NuGet。
首先,我创建了异常筛选器。
public class ErrorLoggingExceptionFilter : IAutofacExceptionFilter
{
public void OnException(HttpActionExecutedContext context)
{
// do something
}
}
然后,将AutofacControllerConfiguration属性
下面的类在构造函数上使用一个原语,因此我需要告诉AutoFac如何使用委托生成上述值:
public class BackgroundTaskScheduler : IStartable
{
private readonly IJobRunner _jobRunner;
private int _triggerMilliseconds;
public BackgroundTaskScheduler(IJobRunner jobRunner, int triggerMilliseconds)
{
_jobRunner = jobRunner;
我有一个像这样的Autofac Web Api授权过滤器:
public class MyAuthorizationFilter : IAutofacAuthorizationFilter
{
public void OnAuthorization(HttpActionContext actionContext){}
}
public class MyAuthorizationAttribute : Attribute
{
public MyAuthorizationAttribute() { }
}
现在,我可以使用Autofac授权过滤器的唯一方法是在AutofacCon
我在我的web中使用autofac注册log4net。它在控制器中工作得很好,但是如何在相同的解决方案中为公共库项目类使用相同的log4net实例。
我在web中使用下面的代码使用autofac注册log4net。
// IOC Container Setup uisng Autofac
var builder = new ContainerBuilder();
// Register your Web API controllers.
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.Regis
我的服务接口有一个具体的类实现,如下所示:
public class MyService:IService {
public MyService([KeyFilter("sampleone")] IRepository repoToUse) {
_repoToUse = repoToUse;
}
// rest of code
}
我将该服务注册为:
builder.Register(ctx => new CustomRepo()).Keyed<IRepository>("sampleone"
虽然我通常觉得Autofac文档(在wiki上)很有帮助,但关于XML配置和模块的部分对我来说有点不清楚。现在,我有一个样例在工作(我在下面展示),但我不确定它是否代表了一种在Autofac上下文中进行配置的混蛋方法。特别是,我不确定我在配置文件和代码文件中是否有更多或更少我真正需要的东西。
代码如下:
using System;
using System.IO;
using Autofac;
using Autofac.Configuration;
namespace AutofacTest.Animals
{
interface IAnimal
{
voi
我创建了一个"Hello World“应用程序,现在我正尝试在Raspbarry Pi上运行它。当我在publish中选择"Self-containt“时,所有的文件都会被复制到Raspberry中,我就可以执行"Hello World”应用程序了。但是当我选择"Framework-dependant“并将应用程序发布到Raspberry时,当我想要运行它时,我得到了一条错误消息: It was not possible to find any compatible framework version
The framework 'Microsoft.
最近,我们停止使用Autofac,并开始在netcore3.1web和控制台应用程序中使用Microsoft DependencyInjection。我们仍然热爱它们都能完成我们的解耦设计。只要一个简单的决定,使用本机微软包,如果它可以做同样的事情,第三方软件包。下面是我们试图迁移的代码,重点是我们已经通过注册扫描程序集的类型获得了好处,我们希望保持这种设计以降低迁移成本,
RequiredServices.cs
在DI之前,为了防止注册激增(是的,我们确实有100+接口和服务),我们不注册每个服务,而是使用扫描程序集。
public interface IRepository { }
p
我设置了EF核心并使用.Net核心2和EF核心2。我升级到了.Net核心和EF核心到v3,但我从未测试过我的迁移。 现在我已经升级到.NetCore 3.1 & EF Core3.1,当我尝试创建迁移或运行数据库更新时,我得到以下错误。 It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '2.2.0' was not found.
- The following frameworks
我有一个带有EF的dotnet项目。当我试图配置、构建和运行Nuget还原步骤时,会出现以下错误
The nuget command failed with exit code(1) and error(Errors in E:\TFS_Agents2017\...\s\ABC.Employees\ABC.Employees.csproj
Unable to resolve 'Microsoft.NETCore.App (>= 3.1.0)' for '.NETCoreApp,Version=v3.1'.
Errors in E:\TFS_Agen