Tag: open generics

数组的开放generics类型是什么?

当我执行int[] , string[] , T[] – 这是一个通用数组。 数组就像其他所有对象一样。 那么[]的实际开放generics类型是什么? 我假设它只是像Array类的一些语法糖,但我无法找到任何类型的东西。 如果你能在Jon Skeet之前以某种方式回答这个问题,可以获得奖励积分。

如何在SimpleInjector 2.6.1+中unit testing开放的通用装饰器链

给定以下使用SimpleInjector的开放式通用deocrator链: container.RegisterManyForOpenGeneric(typeof(IHandleQuery), assemblies); container.RegisterDecorator( typeof(IHandleQuery), typeof(ValidateQueryDecorator) ); container.RegisterSingleDecorator( typeof(IHandleQuery), typeof(QueryLifetimeScopeDecorator) ); container.RegisterSingleDecorator( typeof(IHandleQuery), typeof(QueryNotNullDecorator) ); 使用SimpleInjector 2.4.0,我能够使用以下代码对此进行unit testing以断言装饰链: [Fact] public void RegistersIHandleQuery_UsingOpenGenerics_WithDecorationChain() { var instance = Container .GetInstance<IHandleQuery>(); InstanceProducer registration = Container.GetRegistration( typeof(IHandleQuery)); instance.ShouldNotBeNull(); registration.Registration.ImplementationType .ShouldEqual(typeof(HandleFakeQueryWithoutValidator)); registration.Registration.Lifestyle.ShouldEqual(Lifestyle.Transient); var decoratorChain = registration.GetRelationships() .Select(x => new { x.ImplementationType, x.Lifestyle, }) .Reverse().Distinct().ToArray(); decoratorChain.Length.ShouldEqual(3); decoratorChain[0].ImplementationType.ShouldEqual( typeof(QueryNotNullDecorator)); decoratorChain[0].Lifestyle.ShouldEqual(Lifestyle.Singleton); decoratorChain[1].ImplementationType.ShouldEqual( typeof(QueryLifetimeScopeDecorator)); […]

如何在Autofac中注册许多开放式通用

我是Autofac的新手 (不是DI )。 情况如下: 我有这些接口: public interface IQuery : IQuery { } public interface IQueryHandler where TQuery : IQuery { TResult Handle(TQuery query); } 在我的解决方案中有很多实现: class GetPersonQuery : IQuery { } class GetPersonQueryHandler : IQueryHandler { } class GetArticleQuery : IQuery { } class GetArticleQueryHandler : IQueryHandler { } class GetSomethingQuery : IQuery<IEnumerable> { } […]

用于公开通用接口的非generics版本的模式

假设我有以下界面来显示分页列表 public interface IPagedList { IEnumerable PageResults { get; } int CurrentPageIndex { get; } int TotalRecordCount { get; } int TotalPageCount { get; } int PageSize { get; } } 现在我想创建一个分页控件 public class PagedListPager { public PagedListPager(IPagedList list) { _list = list; } public void RenderPager() { for (int i = 1; i < […]

从Autofac Builder获取所有AsClosedTypesOf注册变体

让我们假设这些类/接口: public interface ICommand { } public class SomeCommand : ICommand { } public interface ICommandHandler where T : ICommand { void Handle(T arg); } public class SomeCommandHandler : ICommandHandler { void Handle(SomeCommand arg){ /* do something */ } } public interface ICommandBus { void RegisterHandler(T t) where T : ICommandHandler; void RegisterHandlerByParam(ICommandHandler t2) where […]

AutoFixture:配置Open Generics Specimen Builder

我有一个使用Open Generics的对象模型(是的,是的,现在我有两个问题;这就是为什么我在这里:): – public interface IOGF { } class C { } class D { readonly IOGF _ogf; public D( IOGF ogf ) { _ogf = ogf; } } 我正在尝试让AutoFixture生成上面的D匿名实例。 然而,就其本身而言,AutoFixture没有构建IOGF的内置策略,因此我们观察到: public class OpenGenericsBinderDemo { [Fact] public void X() { var fixture = new Fixture(); Assert.Throws( () => fixture.CreateAnonymous() ); } 基本信息是: Ploeh.AutoFixture.ObjectCreationException:AutoFixture无法从IOGF`1 [C]创建实例,很可能是因为它没有公共构造函数,是抽象或非公共类型。 我很高兴为它提供一个具体的实现: […]