草庐IT

c# - .NET 4、AllowPartiallyTrustedCallers 属性和 SecurityCritical 等安全标记

我是C#新手,正在尝试理解newsecurityfeaturesof.NET-4.为了补充一些细节,我目前正在尝试更新AutofacContrib.Moq以使用最新的Moq。对于.NET-3.5及以下版本,我没有遇到任何问题。但在.NET-4中,安全限制会导致大量安全异常。Moq有一个方法,GetObjectData,用SecurityCritical标记属性。AutofacContrib.Moq有AllowPartiallyTrustedCallers作为异常源的属性集。似乎与其添加SecurityLevel为1的SecurityRules属性,不如删除AllowPartiallyT

c# - .NET 4、AllowPartiallyTrustedCallers 属性和 SecurityCritical 等安全标记

我是C#新手,正在尝试理解newsecurityfeaturesof.NET-4.为了补充一些细节,我目前正在尝试更新AutofacContrib.Moq以使用最新的Moq。对于.NET-3.5及以下版本,我没有遇到任何问题。但在.NET-4中,安全限制会导致大量安全异常。Moq有一个方法,GetObjectData,用SecurityCritical标记属性。AutofacContrib.Moq有AllowPartiallyTrustedCallers作为异常源的属性集。似乎与其添加SecurityLevel为1的SecurityRules属性,不如删除AllowPartiallyT

c# - Autofac RegisterInstance 与 SingleInstance

IProductRepositoryProxyProductDataServiceProviderInstance=newServiceProductDataProvider();builder.RegisterInstance(ProductDataServiceProviderInstance).As();对比builder.RegisterType().As().InstancePerRequest();我从一位前雇员那里看到这段代码,想知道这个人是否想注册一个.SingleInstance()行为。builder.RegisterType().As().SingleInstan

c# - Autofac RegisterInstance 与 SingleInstance

IProductRepositoryProxyProductDataServiceProviderInstance=newServiceProductDataProvider();builder.RegisterInstance(ProductDataServiceProviderInstance).As();对比builder.RegisterType().As().InstancePerRequest();我从一位前雇员那里看到这段代码,想知道这个人是否想注册一个.SingleInstance()行为。builder.RegisterType().As().SingleInstan

c# - 使用 Autofac 解析通用接口(interface)

给定以下代码,如何在autofac中解析正确的SomeInstance?publicclassBaseClass{}publicclassSubClass1:BaseClass{}publicclassSubClass2:BaseClass{}publicinterfaceIGenericInterfacewhereT:BaseClass{}publicclassSomeInstance1:IGenericInterfacewhereT:SubClass1publicclassSomeInstance2:IGenericInterfacewhereT:SubClass2我想根据子类的泛

c# - 使用 Autofac 解析通用接口(interface)

给定以下代码,如何在autofac中解析正确的SomeInstance?publicclassBaseClass{}publicclassSubClass1:BaseClass{}publicclassSubClass2:BaseClass{}publicinterfaceIGenericInterfacewhereT:BaseClass{}publicclassSomeInstance1:IGenericInterfacewhereT:SubClass1publicclassSomeInstance2:IGenericInterfacewhereT:SubClass2我想根据子类的泛

c# - 为多个接口(interface)返回相同的实例

我正在使用以下代码注册组件:StandardKernelkernel=newStandardKernel();stringcurrentDirectory=Path.GetDirectoryName(GetType().Assembly.Location)foreach(varassemblyinAppDomain.CurrentDomain.GetAssemblies()){if(!Path.GetDirectoryName(assembly.Location).Equals(currentDirectory))continue;foreach(vartypeinassembly.G

c# - 为多个接口(interface)返回相同的实例

我正在使用以下代码注册组件:StandardKernelkernel=newStandardKernel();stringcurrentDirectory=Path.GetDirectoryName(GetType().Assembly.Location)foreach(varassemblyinAppDomain.CurrentDomain.GetAssemblies()){if(!Path.GetDirectoryName(assembly.Location).Equals(currentDirectory))continue;foreach(vartypeinassembly.G

c# - 使用 Autofac 将参数传递给构造函数

我对autofac很陌生,所以我可能完全滥用了它。假设我有一个具有这种结构的类:publicclassHelperClass:IHelperClass{publicHelperClass(stringa,stringb){this.A=a;this.B=b;}}我有两个使用该类的类,但构造函数需要不同的默认值。第二个构造函数仅用于测试目的——我们总是希望在“真实”应用程序中有一个HelperClass:publicclassDoesSomething:IDoesSomething{publicDoesSomething():this(newHelperClass("do","somet

c# - 使用 Autofac 将参数传递给构造函数

我对autofac很陌生,所以我可能完全滥用了它。假设我有一个具有这种结构的类:publicclassHelperClass:IHelperClass{publicHelperClass(stringa,stringb){this.A=a;this.B=b;}}我有两个使用该类的类,但构造函数需要不同的默认值。第二个构造函数仅用于测试目的——我们总是希望在“真实”应用程序中有一个HelperClass:publicclassDoesSomething:IDoesSomething{publicDoesSomething():this(newHelperClass("do","somet