Questions tagged [open-generics]
54 questions
4
votes
1 answer
Conditional registering decorator for open-generic with autofac
I have these open-generics:
public interface IQuery {}
public interface ICacheableQuery : IQuery {
string CacheKey { get; }
}
public interface IQueryHandler
where TQuery :…

amiry jd
- 27,021
- 30
- 116
- 215
4
votes
5 answers
Is it possible to keep a list of open generic types in one place?
I'm trying to have a List of open generic types. Is it possible to have something like:
public class MessageProcessor
{
private IDictionary> _messageHandlers
= new Dictionary>();
…

Peter
- 13,733
- 11
- 75
- 122
4
votes
2 answers
Composing Open Generic Types with Closed Types in MEF 2
I understand that starting with MEF 2, MEF supports composing open generic types into closed types. I'm trying to compose a closed type from types exported from two different assemblies added to the same composition container and I'm receiving an…

Robb Vandaveer
- 1,481
- 20
- 25
4
votes
2 answers
How do I bind generic types with inheritance using Ninject Conventions extensions
How can I bind InitializerForXXX (non-generic implementation) to IInitializer (generic interface) using Ninject Conventions so that requests for an IInitializer resolve a non-generic implementation whose name starts with InitializerFor and…

Jeff
- 2,191
- 4
- 30
- 49
3
votes
2 answers
Injecting primitive type in constructor of generic type using Microsoft DI
I'm trying to use dependency injection to add a generic service that has constructor parameters. I Need to implement this, generically:
host.Services.AddSingleton(x =>
new Service(x.GetRequiredService(),
…

Javiseeker
- 47
- 1
- 11
3
votes
1 answer
Register open generics with precedence
Is it possible to use unity like so:
container.Register(typeof(IMyType), typeof(MyType1));
container.Register(typeof(IMyType<>), typeof(MyType2<>));
.. so that when I try to resolve IMyType I get a MyType1... but when I try to…

Chris Klepeis
- 9,783
- 16
- 83
- 149
3
votes
2 answers
How to register all implementations of an open generic interface using Autofac
I currently have an interface for a single step in a pipeline.
public interface IPipelineStep
where T1: ModelObject
where T2: EntityObject { }
And I have a whole bunch of steps that implement this interface:
public class…

Aaron
- 282
- 1
- 4
- 11
3
votes
2 answers
Castle Windsor: Conditional registration of open generic types
I have the following:
class Repository : IRepository
interface ISuperRepository : IRepository
class SuperRepository : ISuperRepository
interface ISuperType
I want conditional registration in Castle Windsor DI for IRepository,…

Rita
- 1,448
- 1
- 14
- 22
3
votes
1 answer
C# Inherited Open Generics Compile
Today my brain went dead, and I couldn't figure out a clean way of forcing the compiler to use inheritance for Generic inference.
Imagine the following 4 classes
Models
public abstract class Model
{
}
public class CodePerfModel :…

Michal Ciechan
- 13,492
- 11
- 76
- 118
3
votes
2 answers
How to unit test open generic decorator chains in SimpleInjector 2.6.1+
Given the following open generic deocrator chain using SimpleInjector:
container.RegisterManyForOpenGeneric(typeof(IHandleQuery<,>), assemblies);
container.RegisterDecorator(
typeof(IHandleQuery<,>),
…

danludwig
- 46,965
- 25
- 159
- 237
3
votes
1 answer
StructureMap instance factory method
I'm trying to register a factory method for creating instances of an open generic type MongoCollection<>. However, when I GetInstance it appears that it is using a constructor of MongoCollection instead of the factory method.
var mongo = new…

kelloti
- 8,705
- 5
- 46
- 82
2
votes
1 answer
How to declare variable for open generic type? Possible?
Is there a way to declare a vaiable for an open generic type?
Given: There is a generic class Logger that users get from a factory method. Is there a way to have a variable that can hold ANY logger?
Right now Logger inherits from Logger ONLY for…

TomTom
- 61,059
- 10
- 88
- 148
2
votes
1 answer
AutoMapper Open Generics Mapping Not Working
I am trying to setup a map to utilize open generics, but it never works at runtime. I'm using AutoMapper 5.2 in .NET Core.
I have these models:
public interface IRestData
{
T Data { get; }
IPaging Paging { get; }
void SetData(T…

Ristogod
- 905
- 4
- 14
- 29
2
votes
2 answers
Open Generics and IEnumerable with Ninject
I have the following interface...
public interface IHandler where TFor : IRequest
{
void Handle(IEnumerable requests);
}
which is typically implemented like so...
public class AssignmentHandler : HandlerBase,…

Baldy
- 3,621
- 4
- 38
- 60
2
votes
1 answer
Is it possible to use Ninject Factory Extensions' ToFactory method with open generics?
I'm building on a previously answered question in which ICar implementations are bound using Ninject Conventions Extensions and a custom IBindingGenerator, and the ICarFactory interface is bound using the Ninject Factory Extensions' ToFactory()…

Jeff
- 2,191
- 4
- 30
- 49