Skip to content

Question: Registering Generic Singleton #409

Open
@Mike-E-angelo

Description

@Mike-E-angelo

Got another one for you. :)

Consider the following class:

sealed class Singleton<T> : ISource<T>
{
	public static Singleton<T> Default { get; } = new Singleton<T>();
	Singleton() {}

	public T Get() => default(T);
}

Up until now I have been using RegisterInstance with no problem. However, here the generics again add yet another wrinkle. What would be ideal is to have a Register(Type type, Func<IServiceFactory, object> factory) but there does not appear to be one, not that I can find at least. Is there a way to do something like this that I might be overlooking?

The other issue I have been running into is that I have tried RegisterFallback but it never reaches it because my constructor selector throws an exception when it cannot find any constructors on the above class (since it's private).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions