Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 20 06:37
    dylel commented #290
  • Sep 08 22:24
    hellfirehd edited #294
  • Sep 08 21:25
    jdub4237 commented #294
  • Sep 08 21:11
    jdub4237 commented #294
  • Sep 08 21:00
    jdub4237 commented #294
  • Sep 08 17:06
    hellfirehd opened #294
  • Sep 03 07:21

    github-actions[bot] on gh-pages

    Documentation Update for 5.0.0 (compare)

  • Sep 03 07:19

    mysticmind on master

    Update Algolia config [skip ci] (compare)

  • Sep 02 08:29

    github-actions[bot] on gh-pages

    Documentation Update for 5.0.0 (compare)

  • Sep 02 08:23

    mysticmind on master

    Update docs.yml (compare)

  • Sep 02 08:19

    mysticmind on master

    Add GH action and build to publ… (compare)

  • Sep 02 08:16

    mysticmind on master

    Add GH action and build to publ… (compare)

  • Aug 24 16:01

    mysticmind on gh-pages

    Documentation Update for 5.0.0 (compare)

  • Aug 24 16:00

    mysticmind on master

    Update docs algolia config (compare)

  • Aug 24 15:53

    mysticmind on gh-pages

    Documentation Update for 5.0.0 (compare)

  • Aug 24 15:39

    mysticmind on master

    Update algolia search config (compare)

  • Aug 23 17:23
    jansssson commented #293
  • Aug 23 17:22
    jansssson commented #293
  • Aug 23 17:22
    jansssson closed #293
  • Aug 23 15:58
    jeremydmiller commented #293
Nicholas Budd
@anaximander23
or better yet, wherever you're currently calling container.GetInstance<IGrid>("whatever") to get your controls, instead just inject the grid factory into that thing and ask it to create your controls
rather than having a reference to the container there and using the container as a makeshift factory
Maulik Modi
@maulik-modi
container.Getinstance is borrowed from Lamar docs, I was checking if it is possible to pass "whatever" name to help resolving the right grid
Jeremy D. Miller
@jeremydmiller
@maulik-modi Lamar supports resolving services by name: https://jasperfx.github.io/lamar/guide/ioc/resolving/get-a-service-by-plugin-type-and-name.html. It's just an overload of GetInstance<T>(name)
And I'd just echo what @anaximander23 said. Lamar will not be supporting any kind of Json or Xml configuration other than what you do yourself through lambdas and IConfiguration
Maulik Modi
@maulik-modi
yes, happy to use IConfiguration
Mark Warpool
@CodingGorilla
I would add to the chorus of supporting what @anaximander23 about using a factory class (FWIW :smiley: )
Nicholas Budd
@anaximander23
@jeremydmiller so I did manage to narrow down what was happening with the HttpClient registrations
in the ServiceRegistry, if you do this.AddHttpClient<MyClient>(ConfigureAction); and then For<IService>().Use<MyService>().Ctor<IClient>().Is<MyClient>(); then when you resolve IService it creates a MyClient instance on the fly and doesn't seem to use the earlier registration, which means that ConfigureAction(...) is never called
I presume because it's adding a registration for something slightly different and therefore can't tell that it should use that, but it looks at the constructors on MyClient and figures out that it can create one anyway
if you change the constructor parameter on MyService to be of type MyClient instead of IClient then it works fine, and you don't even need the Ctor<IClient>()... bit
but then you're depending on a concrete class again
Jeremy D. Miller
@jeremydmiller
Yeah, you're using an explicit registration as the inline dependency to MyService, that makes sense. Usually better/easier to rely on auto-wiring
Nicholas Budd
@anaximander23
ah, so the inline dependency adds a new registration rather than looking for an existing registration matching that type?
main reason I tried it that was is because there's two things that implement IClient and I need to choose which
Jeremy D. Miller
@jeremydmiller
Yes. Remember that Lamar — and propably every other DI container — never keys off the implementation type. There’s no magic “let me go find the registration that matches this concrete type”. And inline dependencies are just new “inline” dependencies. You can set it to a named instance though, if that helps
Doesn’t seem to be in teh docs, but you can refer to a named registration of the service type when you do an inline registration. That’s an old, old StructureMap thing that got ported over to Lamar
Nicholas Budd
@anaximander23
yeah, I spotted that overload, but it doesn't seem to work with named HttpClient registrations via the Microsoft extension method
at least, not the way that I tried it
but in theory I could do Ctor<IClient>().Use<ISpecificClient>() and just add in some marker interfaces
Jeremy D. Miller
@jeremydmiller
That refers to Lamar names, so it has nothing to do with the HttpClientFactory
Nicholas Budd
@anaximander23
and essentially just redirect from the more general interface to a more specific one, and then it would use the registration added via the extension method
Jeremy D. Miller
@jeremydmiller
You won’t be able to directly register an interface to another interface. You can use a Lambda registration to effectively forward one to the other.
What are you actually trying to achieve?
Nicholas Budd
@anaximander23
  • bunch of services with ordinary registrations (For<IServiceA>().Use<ServiceA>();)
  • MyHttpClient implements IHttpClient, has the regular System.Net.Http.HttpClient as a dependency, and adds some other stuff that's not really relevant
  • each of the services depends on IHttpClient, and can use the same implementation, but a different config because they talk to different APIs, so as a minimum they need their BaseAddress to be different (and possibly other things relating to those APIs' policies wrt. auth, caching, rate limits, etc)
so I just need Lamar to know a few different ways of constructing an instance of MyHttpClient, and to know which one to use for each service
Jeremy D. Miller
@jeremydmiller
Gotcha. Might be easier in the end to just inject HttpContextFactory and pull things from there within each service gateway
Nicholas Budd
@anaximander23
yeah, looks like it's either that or just empty marker interfaces like IHttpClientA : IHttpClient so that services each depend on whichever specific client interface they need
which tbf isn't all that bad, conceptually, since it indicates a functional difference in implementations that they do depend on
it just so happens that that difference can be implemented by having a different value of base URL, but that's just an implementation detail
Mark Warpool
@CodingGorilla
@jeremydmiller With the upgrade to v6, I'm immediately getting the following at start up:
System.Reflection.TargetInvocationException
  HResult=0x80131604
  Message=Exception has been thrown by the target of an invocation.
  Source=System.Private.CoreLib
  StackTrace:
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance[T]()
   at Jasper.HostBuilderExtensions.UseJasper[T](IHostBuilder builder, Action`2 overrides)
   at LaMotte.Api.Program.CreateHostBuilder(String[] args) in C:\Users\CeeGee\Source\Repos\LaMotte.Api\src\LaMotte.Api\Program.cs:line 22
   at LaMotte.Api.Program.Main(String[] args) in C:\Users\CeeGee\Source\Repos\LaMotte.Api\src\LaMotte.Api\Program.cs:line 18

Inner Exception 1:
MissingMethodException: Method not found: 'Lamar.IoC.Instances.ConstructorInstance`1<!!0> InstanceExpression`1.Use()'.
Maybe an incompatibility with Jasper?
Jeremy D. Miller
@jeremydmiller
No idea, so go back to Lamar 5:)
Nevermind, MissingMethodException always means incompatible dependencies
Mark Warpool
@CodingGorilla
yea, I rolled back... wanted to pass it on though
Jeremy D. Miller
@jeremydmiller
I did start the work to upgrade Jasper to .Net 5 and Marten 4, plus other things. Not really that close yet.
Mark Warpool
@CodingGorilla
no problem, I will probably skip .NET 5 and go straight to 6 when it releases, so I have time :)
Edward May
@eMarkM

I have a question about how ForConcreteType works. I have a factory which has many impls of ISuccessorCommand which is filled by call to scanner.AddAllTypesOf<ISuccessorCommand>()

public class CommandFactory : ICommandFactory
{
private readonly ISuccessorCommand[] _commands;

    public CommandFactory(ISuccessorCommand[] commands)
    {
        _commands = commands;
    }

    public ISuccessorCommand Get(string name)
    {
        ISuccessorCommand cmd = _commands.FirstOrDefault(c => c.Name == name);

        if (cmd == null)
            throw new CommandException($"Cannot find a command named {name}");

        return cmd;
    }

}

But for some of these I want to use setter injection such as follows:
ForConcreteType<TestCommand>().Configure.Setter<IExecutionStrategy>().Is<TestCommandExecutionStrategy>();

These don't get injected when when accessing via the factory. They come through if I inject the concreate class. But I'm going to have a LOT of these ISuccessorCommand objects and didn't want to inject each individually into classes that need them as the ctors might then get dozens of these concrete classes. I was looking to just inject the factory and then the client can get what it needs by calling the Get method. I guess I was under the impression the ForConcreteClass would do this config even if you're not directly injecting them somewhere. Is there a way to do this? Thanks

inthegarden
@inthegarden

Stack overflow.
at System.RuntimeTypeHandle.IsCollectible(System.Runtime.CompilerServices.QCallTypeHandle)
at System.RuntimeType.get_IsCollectible()
at System.Dynamic.Utils.TypeExtensions.GetParametersCached(System.Reflection.MethodBase)
at System.Dynamic.Utils.ExpressionUtils.GetParametersForValidation(System.Reflection.MethodBase, System.Linq.Expressions.ExpressionType)
at System.Dynamic.Utils.ExpressionUtils.ValidateArgumentTypes(System.Reflection.MethodBase, System.Linq.Expressions.ExpressionType, System.Collections.ObjectModel.ReadOnlyCollection1<System.Linq.Expressions.Expression> ByRef, System.Stri ng) at System.Linq.Expressions.Expression.New(System.Reflection.ConstructorInfo, System.Collections.Generic.IEnumerable1<System.Linq.Expressions.Expression>)
at Lamar.IoC.Instances.InstanceConstructorFrame.WriteExpressions(LamarCodeGeneration.Expressions.LambdaDefinition)
at Lamar.IoC.Instances.InlineLambdaCreationFrame1[[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteExpressions(LamarCodeGeneration.Expressions.LambdaDefinition) at Lamar.IoC.Instances.InstanceConstructorFrame.WriteExpressions(LamarCodeGeneration.Expressions.LambdaDefinition) at Lamar.IoC.Instances.InlineLambdaCreationFrame1[[System.Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteExpressions(LamarCodeGeneration.Expressions.LambdaDefinition)
at Lamar.IoC.Instances.InstanceConstructorFrame.WriteExpressions(LamarCodeGeneration.Expressions.LambdaDefinition)
at Lamar.IoC.Instances.InstanceConstructorFrame.WriteExpressions(LamarCodeGeneration.Expressions.LambdaDefinition)
at Lamar.IoC.Instances.InstanceConstructorFrame.WriteExpressions(LamarCodeGeneration.Expressions.LambdaDefinition)
.
. //Lots of similar calls repeated
.
at Lamar.IoC.Instances.InlineLambdaCreationFrame`1[[System.
Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteExpressions(LamarCodeGeneration.Expressions.LambdaDefinition)
at Lamar.IoC.Instances.InlineLambdaCreationFrame1[[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteExpressions(LamarCodeGeneration.Expressions.LambdaDefinition) at Lamar.IoC.Instances.InstanceConstructorFrame.WriteExpressions(LamarCodeGeneration.Expressions.LambdaDefinition) at Lamar.IoC.Instances.InlineLambdaCreationFrame1[[System.Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteExpressions(LamarCodeGeneration.Expressions.LambdaDefinition)
at Lamar.IoC.Instances.InstanceConstructorFrame.WriteExpressions(LamarCodeGeneration.Expressions.LambdaDefinition)
at Lamar.IoC.Frames.GetInstanceFrame.WriteExpressions(LamarCodeGeneration.Expressions.LambdaDefinition)
at Lamar.IoC.Instances.InlineLambdaCreationFrame`1[[System.
Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteExpressions(LamarCodeGeneration.Expressions.LambdaDefinition)
at Lamar.IoC.Instances.FuncResolverDefinition.BuildResolver()
at Lamar.IoC.Instances.GeneratedInstance.BuildFuncResolver(Lamar.IoC.Scope)
at Lamar.IoC.Instances.GeneratedInstance.buildResolver(Lamar.IoC.Scope)
at Lamar.IoC.Instances.GeneratedInstance.ToResolver(Lamar.IoC.Scope)
at Lamar.IoC.Instances.ConstructorInstance.ToResolver(Lamar.IoC.Scope)
at Lamar.ServiceGraph.FindResolver(System.Type)
at Lamar.IoC.Scope.TryGetInstance(System.Type)
at Lamar.IoC.Scope.GetService(System.Type)
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(System.IServiceProvider, System.Type, System.Type, Boolean)

In general, what is this pattern indicative of? Circular reference? I fully appreciate this is a bit of vague one so apologies up front!

Jeremy D. Miller
@jeremydmiller
Probably a circular type reference, yes. Do you know what type it's trying to resolve (or really in this case just plan out)? I've seen it occasionally when something has a constructor for Expression I think.
inthegarden
@inthegarden
Thanks for the instant response @jeremydmiller ! I will have a hunt around.
inthegarden
@inthegarden
I have located the issue. I have IFormViewFactory with a concrete type of FormViewFactory; if I inject IFormViewFactory into an ASP.NET Core Controller it throws the Stack Overflow exception as above. As a test I injected all of the dependencies of FormViewFactory into a controller, no exception. There's no reference to IFormViewFactory in my service registry classes. I'm a little confused now!
I do have one constructor with an Expression in it public MatchProperty(Expression<Func<T, TOther>> expr, TOther value) but have yet to confirm that is in play here.
Jeremy D. Miller
@jeremydmiller
Are you doing some type scanning?
inthegarden
@inthegarden
I believe so, not in office at the moment, will respond first thing in the (UK) morning 👍
Bill Robertson
@billrob
Is there a link to any breaking changes from v5 to v6?
Jeremy D. Miller
@jeremydmiller
Sorry, no. It’s very unlikely you’ll hit anything. If you compile, you’re good.
Bill Robertson
@billrob
Thanks. Just using basic features, so prolly all good