Questions tagged [open-generics]

54 questions
148
votes
4 answers

What exactly is an "open generic type" in .NET?

I was going through Asp.Net MVC lesson and learned that, for a method to qualify as an action for a controller, It must not have an "open generic type" I understand generics somewhat and use them to some extent, but: What is an open generic type…
Asad
  • 21,468
  • 17
  • 69
  • 94
74
votes
4 answers

Get all types implementing specific open generic type

How do I get all types that implementing a specific open generic type? For instance: public interface IUserRepository : IRepository Find all types that implement IRepository<>. public static IEnumerable
Rookian
  • 19,841
  • 28
  • 110
  • 180
26
votes
3 answers

Pattern for exposing non-generic version of generic interface

Say I have the following interface for exposing a paged list public interface IPagedList { IEnumerable PageResults { get; } int CurrentPageIndex { get; } int TotalRecordCount { get; } int TotalPageCount { get; } int…
fearofawhackplanet
  • 52,166
  • 53
  • 160
  • 253
26
votes
2 answers

How to register many for open generic in Autofac

I'm new to Autofac (not to DI). Here is the situation: I have these interfaces: public interface IQuery : IQuery { } public interface IQueryHandler where TQuery : IQuery { TResult Handle(TQuery…
amiry jd
  • 27,021
  • 30
  • 116
  • 215
16
votes
4 answers

Higher-order type functions in TypeScript?

Please consider the following pseudo-code trying to define a higher-order type function with a function-typed parameter M: type HigherOrderTypeFn> = T extends (...) ? M : never; M is syntactically incorrect TypeScript, but…
brncsk
  • 173
  • 1
  • 5
10
votes
2 answers

AutoFixture: Configuring an Open Generics Specimen Builder

I have an object model that uses Open Generics (Yes, yes, now I have two problems; that's why I'm here :) :- public interface IOGF { } class C { } class D { readonly IOGF _ogf; public D( IOGF ogf ) { _ogf = ogf; …
Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
7
votes
1 answer

What is the correct way to register FluentValidation with Simple Injector?

I am able to register FluentValidation AbstractValidators using a FluentValidatorFactory. However, it doesn't feel right, because not all of the IoC container registrations happen during bootstrap / composition root. Instead, the fluent validators…
7
votes
1 answer

Automapping using open generics and including the source in a ForMember statement

I've recently upgraded from Automapper 4.2.1 to 5.1.1 and am having issues with a previously valid mapping involving open generics. Previously, within the automapper configuration, I had the following open generic mapping…
rheone
  • 1,517
  • 1
  • 17
  • 30
6
votes
2 answers

SimpleInjector HowTo Register multiple Open Generic Interfaces for a Single Generic Implementation

I'm trying to get started with SimpleInjector as an IOC Container and up to now I'm pretty happy with it. But right now I'm stuck on a problem I can't solve. I searched on SO and in the documentation, but it seems to be not answered yet. I've seen…
Kai
  • 871
  • 2
  • 18
  • 39
5
votes
2 answers

Autofac decorating open generics registered using assembly scanning

I'm trying to apply autofac decorator support feature to my scenario with no success. It looks like in my case it doesn't assign the name to the registrations properly. Is there a way to register scanned assembly types with a name, so that I can…
achekh
  • 1,106
  • 7
  • 20
5
votes
0 answers

How to resolve all service types for the full hierarchy of a closed generic's closure type

I have recently begun using autofac, migrating away from structuremap and lamar. With the previous dependency injection tools it was seemingly rather trivial to resolve all services that closed on the full hierarchy (all interfaces, and base…
rheone
  • 1,517
  • 1
  • 17
  • 30
5
votes
2 answers

Type constrained open generics do not work with RegistrationBuilder

The code below does not work when RegistrationBuilder is used. When the RegistrationBuilder is not added to the AssemblyCatalog constructor, type constrained generics work. [TestClass] public class TypeConstraints { [TestMethod] public void…
Roman Dvoskin
  • 384
  • 4
  • 16
5
votes
2 answers

How can I register a generic object factory?

I have the following two classes: public class KeyedEntity { internal KeyedEntity() { } public Identifier Key { get; set; } public TEntity Entity { get; set; } } public static class KeyedEntity { public static…
Sam
  • 40,644
  • 36
  • 176
  • 219
4
votes
4 answers

What is the open generic type of the array []?

When I do int[], string[], T[] - this is a generic array. An array is just an object like everything else. So what is the actual open generic type of []? I assume it is just some syntactic sugar over something like Array<> but I haven't been able…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
4
votes
1 answer

How to automatically register open generic interface with Castle Windsor?

I need to automatically register my open generic interface to its implementation classes My interface is something like that IIntegrationEventHandler public interface IIntegrationEventHandler where TIntegrationEvent :…
1
2 3 4