Coder Social home page Coder Social logo

Comments (7)

alexyakunin avatar alexyakunin commented on May 2, 2024

That's interesting. Am I right the proposal implies:

  1. Adding ~ IMethodBasedFactory - an interface you can extend
  2. Adding ~ IServiceCollection.AddMethodBasedFactory<TFactory>() where TFactory: IMethodBasedFactory, which resolves to a proxy acting as you've described. I.e. it automatically wires up any method call on it to an implementation, which create the actual object relying on ActivatorUtilities.CreateFactory & method call arguments.

And ultimately, it allows to replace untyped ~ services.Activate(...) calls with typed ~ myFactory.CreateSomething(...), + also boost the performance of such calls due to activator/factory caching?

from stl.fusion.

alexyakunin avatar alexyakunin commented on May 2, 2024

I'd also add proxy support for that, btw - i.e. auto-replacement of a type with Stl.Interception proxy, if it's available for that type (coz most likely that's the expected outcome in such cases).

from stl.fusion.

alexyakunin avatar alexyakunin commented on May 2, 2024

@AliveDevil I like the idea - it feels handy, + moreover, if the "default" construction helper won't fit some specific case, you can always add extension methods to the interface for custom construction.

from stl.fusion.

alexyakunin avatar alexyakunin commented on May 2, 2024

If you have some time, please send this PR - I'll definitely accept it, though might make some changes afterwards :)

And I'll be happy to do this anyway at some point (not sure when yet) - I like the proposal.

P.S. Great you dug pretty far into that - this part is almost undocumented.

from stl.fusion.

AliveDevil avatar AliveDevil commented on May 2, 2024

I like IMethodBasedFactory - sounds good.
Adding MethodBasedActivatorUtilitiesInterceptor for this as the interception proxy (using the ActivatorUtilities factory).

Does Stl have any support of dynamic proxies (not generated through Stl.Generation)? Otherwise making IMethodBasedFactoryDefaultProxy could be a challenge (or I'm missing something here).

P.S. Great you dug pretty far into that

If there's no documentation, I'm really stubborn and dig into everything until I have a solution.
Not the best habit in terms of time-efficiency, but for some personal project it works out fine.

from stl.fusion.

AliveDevil avatar AliveDevil commented on May 2, 2024

[…] boost the performance of such calls due to activator/factory caching?

I'd not want to vouch for that, though it makes it way more type-safe and improves discoverability - the factory caching does make it faster, as there is just the initial discovery phase of the constructor, then the factory delegate performs a regular constructor call.

The ObjectFactory itself is using params object[] internally, so whether that makes any difference I'm not sure about - as all value types are boxed again.

I mean, there is the option of porting back ActivatorUtilities1 to not rely on object[] args, but that may overshoot the goal by miles.

Footnotes

  1. https://github.com/dotnet/runtime/blob/release/8.0/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs#L218-L241

from stl.fusion.

AliveDevil avatar AliveDevil commented on May 2, 2024

You are free to edit the PR, it’s „allow edit for maintainers“ enabled.

from stl.fusion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.