'Resolving dependencies with autofac (typeof vs generic)

I was wondering if any of you are aware of the bellow lines of code producing different result:

This line resolves normally

var repo1 = ComponentContext.Resolve(typeof(IVersionedRepository<TR, T>));

while this one doesn't, it basically says the registration is not found. It must be something do to the way I registered the component and it' services, but my understanding was that the generic overload was just a shortcut to the non-generic.

var repo2 = ComponentContext.Resolve<IVersionedRepository<TR, T>>();

This forces me to then cast like the bellow which is not ideal, it works fine but it just makes the code less clean:

repository = ComponentContext.Resolve(typeof(IVersionedRepository<TR, T>)) as IVersionedRepository<TR, T>;

Maybe they execute in a different way, but my assumption was that the generic overload would also use typeof.

This is the registration I am using:

builder.RegisterGeneric(typeof(VersionedRepository<,>))
    .As(typeof(IVersionedRepository<,>))
    .InstancePerDependency()
    .AsSelf()
    .PropertiesAutowired();

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source