aliostad / CacheCow

An implementation of HTTP Caching in .NET Core and 4.5.2+ for both the client and the server
MIT License
847 stars 172 forks source link

CacheCow.Server.DefaultCacheDirectiveProvider registration problems in v2.7.4 #254

Closed memeny closed 4 years ago

memeny commented 4 years ago

I have tried v2.7.4 and am now having problems with my Autofac registration code, using the "standard" method to register CacheCow's internal implementations:

        CachingRuntime.RegisterDefaultTypes(
            (t1, t2, isTransient) => {
                if (isTransient)
                    builder.RegisterType(t2).As(t1);
                else
                    builder.RegisterType(t2).As(t1).SingleInstance();
            });

The reported exception is:

"System.ArgumentException: 'The type 'CacheCow.Server.DefaultCacheDirectiveProvider1[TViewModel]' is not assignable to service 'CacheCow.Server.ICacheDirectiveProvider1'.'"

aliostad commented 4 years ago

Hi, the issue is that in AutoFac, registering a type is different from registering a generic type and you need to use RegisterGeneric.

As such, just add a condition:

if (t1.IsGeneric)
      builder.RegisterGeneric(t2).As(t1);
else
     ....

So it is just the way Autofac works.

Does this help?

memeny commented 4 years ago

Thanks Ali, that’s sorted it.

Presumably you have added some generic types to v2.7.4 – great that I’ve been able to upgrade now.

Thanks again for your efforts with this library – really useful.

From: Ali Kheyrollahi notifications@github.com Sent: 13 July 2020 21:08 To: aliostad/CacheCow CacheCow@noreply.github.com Cc: Mark Emeny mark@littlemansolutions.net; Author author@noreply.github.com Subject: Re: [aliostad/CacheCow] CacheCow.Server.DefaultCacheDirectiveProvider registration problems in v2.7.4 (#254)

Hi, the issue is that in AutoFac, registering a type is different from registering a generic type and you need to use RegisterGeneric.

As such, just add a condition:

if (t1.IsGeneric)

  builder.RegisterGeneric(t2).As(t1);

else

 ....

So it is just the way Autofac works.

Does this help?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/aliostad/CacheCow/issues/254#issuecomment-657764803, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AF2MKQFRIMYL3ULY4DK7DETR3NSRHANCNFSM4OYKKJJA.

aliostad commented 4 years ago

Awesome! Thanks for using CacheCow.