Questions tagged [open-generics]
54 questions
1
vote
1 answer
Register open generic types for all types implementing some interface with StructureMap
I want to register all my types implementing IManager so that they can be used as the type T for the generic Lazy class.
For example:
public TetraRadioPropertyUpdater(Lazy lazyRadioManager)
I use a self made scanner because my…

leozilla
- 1,296
- 2
- 19
- 29
1
vote
1 answer
how to implement Open Generic Constructor Injection in Dot Net Core
I have an interface for Audit Logging:
public interface IAuditDbContext
{
T1 AuditLog { get; set; }
T2 ChangeTracker { get; }
}
now in main AppDbContext interface, I am inheriting this as:
public interface IAppDBContext :…

anurag singh
- 21
- 2
1
vote
1 answer
Does AutoMapper support Open Generics with inheritance from a non-generic base class?
The AutoMapper version # is 7.0.0.
Take the following set of classes:
public class Person
{
public string Name { get; set; }
public List BarList { get; set; }
}
public class PersonModel
{
public string Name { get; set; }
…

Marx
- 113
- 12
1
vote
1 answer
Castle Windsor registering open generics ILogger
I have Simple Injector registration of my:
container.RegisterConditional(typeof(ILogManager),
c => typeof(LogManager<>).MakeGenericType(c.Consumer.ImplementationType),
Lifestyle.Singleton,
c => true);
I need to register same LogManager in different…

DrArqon
- 153
- 1
- 11
1
vote
2 answers
Is there a way to create a nested open generic type?
In C# it is easy to create an open generic type, typeof(IEnumerable<>). Is there a way to create a type that contains an open generic? The following does not work: typeof(IEnumerable>).

myermian
- 31,823
- 24
- 123
- 215
1
vote
1 answer
How to register and resolve open generic with two type arguments as interface with one type argument using Autofac
Problem
I have a number of concrete, generic classes with two type arguments that implement a generic interface with one type argument. For example:
public interface ISomeService
{
// ...
}
public class SomeService :…

prlcutting
- 379
- 2
- 12
1
vote
1 answer
Structuremap returning wrong instance for open generic type?
I am trying to use structuremap with open generic to get instances of a Event handler at run time ,I am using open generic based configuration
// #1 Configuration
scan.ConnectImplementationsToTypesClosing(typeof(IHandle<>));
// #2…

Pratik
- 868
- 1
- 9
- 24
1
vote
1 answer
Automapper and Open Generics
I'm trying to use Automapper's Open Generics as described in https://github.com/AutoMapper/AutoMapper/wiki/Open-Generics to perform a mapping between User and Account.
public class User
{
public Guid UserId { get; set; }
public string…

Bryan
- 5,065
- 10
- 51
- 68
1
vote
1 answer
How to use composite handler with nested open generic?
public interface IMessage { }
public interface ICommand : IMessage { }
public interface IEvent : IMessage { }
public interface IMessageHandler {
void Handle(T message);
}
public class ItemCreatedEvent : IEvent {
public string Name {…

oguzh4n
- 682
- 1
- 10
- 29
1
vote
0 answers
Castle Windsor register closed - open generic
public interface IProcess {}
public interface IProcessHandler where TProcess : IProcess {
void Handle(TProcess message);
}
public class AccessMessage : IProcess where TProcess : IProcess {
public virtual string…

oguzh4n
- 682
- 1
- 10
- 29
1
vote
1 answer
Using Ninject custom instance providers to bind successfully using factory method argument to resolve
I've been studying this accepted answer to a similar question in which what I believe is a concrete factory returns an implementation based on a string argument on the factory method matching a named binding on the concrete implementation.
I'm…

Jeff
- 2,191
- 4
- 30
- 49
0
votes
0 answers
Are "partially" unbound generics possible?
I came across Generics open and closed constructed types this question and started toying around with typeof. I am now wondering why I can do this:
var t = typeof(IPipelineBehaviour<,>);
but not this
var s =…

Benj
- 889
- 1
- 14
- 31
0
votes
0 answers
How to register an open generic that accepts parameters in LightInject?
I have the following generic class, which depends on IBar:
public class Foo : IFoo
{
public Foo(IBar bar, int value) { }
...
}
I would ideally register it using something like this in LightInject:
container.Register

Gyum Fox
- 3,287
- 2
- 41
- 71
0
votes
1 answer
Using open generics with tuples is not working in AutoMapper 10
I have the following two POCOs:
private class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
private class PersonDto
{
public string Name { get; set; }
public int Age { get; set; }
}
Then I defined two…

Collin Alpert
- 475
- 6
- 14
0
votes
2 answers
C#: Construct Type Constrained Half-Closed Generic Implementations of Open Generic Interface via Open Generic Method/Class
I am trying to construct instances of an open generic repository interface whereby the implementations impose more strict type constraints than the interface. Each implementation of the repository interface needs a specific implementation of the…

G.T.D.
- 386
- 1
- 5
- 21