servicetitan / Stl.Fusion

Build real-time apps (Blazor included) with less than 1% of extra code responsible for real-time updates. Host 10-1000x faster APIs relying on transparent and nearly 100% consistent caching. We call it DREAM, or Distributed REActive Memoization, and it's here to turn real-time on!
MIT License
1.85k stars 108 forks source link

Add TypeFactory #650

Closed AliveDevil closed 11 months ago

AliveDevil commented 11 months ago

Full interface for TypeFactory:

// Convention Scoped
AddScopedTypeFactory<TFactory>()
AddScopedTypeFactory<TFactory, TProxy>()
AddScopedTypeFactory<TFactory, TInterceptor>()

// Convention Singleton
AddSingletonTypeFactory<TFactory>()
AddSingletonTypeFactory<TFactory, TProxy>()
AddSingletonTypeFactory<TFactory, TInterceptor>()

AddTypeFactory<TFactory>()
AddTypeFactory<TFactory, TProxy>()
AddTypeFactory<TFactory, TInterceptor>()
AddTypeFactory<TFactory, TProxy, TInterceptor>()
AddTypeFactory(Type, Type)
AddTypeFactory(Type, Type, Type)

UseTypeFactories()

Remarks:

Resolves #649

alexyakunin commented 11 months ago

Hi, I'll merge this. One q: do you think we can come up with something better than "MethodBased"? Just want to know if you have some ideas on that - I tend to dislike unnecessarily long names, but struggle to find a name that describes this well :)

alexyakunin commented 11 months ago

Maybe something like "AutoFactory"?

alexyakunin commented 11 months ago

(just throwing some ideas, i.e. this is not my preference)

AliveDevil commented 11 months ago

So, my ideas:

So AddClassFactoy, AddTypeFactory, AddAutoFactory. With "Add(Singleton|Scoped)". Don't know whether Transient would be necessary.

Auto Factory is fine as well. Not that good either with naming things.

AliveDevil commented 11 months ago

Renamed to TypeFactory and made some changes to how this extension can be consumed (overwrite either Proxy or Interceptor type). TypeFactory now takes class, IRequiresAsyncProxy, which should be sufficient. Adding an interface just for annotation seemed a bit too much, as there already is Requires Async Proxy.

alexyakunin commented 11 months ago

LGTM, will merge this PR today or tomorrow - thanks!

alexyakunin commented 11 months ago

@AliveDevil I slightly edited this, but no changes to the way it works: https://github.com/servicetitan/Stl.Fusion/commit/49c60c13e080acbe64627aa4c552f468c79aa875

Mostly, it's "TypeFactory" -> "TypedFactory", + I removed a bunch of excessive methods :)

alexyakunin commented 11 months ago

And added one more test.