Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 07:52
    hahn-kev commented #199
  • Oct 21 16:36

    jeremydmiller on master

    adjustments to the IGeneratesCo… (compare)

  • Oct 19 15:11
    StuartFergusonVme opened #199
  • Oct 18 19:25

    jeremydmiller on master

    bumping version in appveyor (compare)

  • Oct 18 19:20

    jeremydmiller on master

    bumping other versions (compare)

  • Oct 18 19:16

    jeremydmiller on master

    4.0 Release -- depending on Bas… (compare)

  • Oct 18 18:04

    jeremydmiller on master

    Bumping versions for maintenanc… (compare)

  • Oct 18 12:15
    blemasle commented #189
  • Oct 18 09:40
    jeremydmiller commented #194
  • Oct 18 05:30
    stefandascalu64 commented #194
  • Oct 18 05:30
    stefandascalu64 commented #194
  • Oct 18 05:29
    stefandascalu64 commented #194
  • Oct 17 20:43
    jeremydmiller commented #198
  • Oct 17 20:39
    jeremydmiller commented #185
  • Oct 17 20:37
    jsheetzati commented #198
  • Oct 17 20:37
    jeremydmiller closed #186
  • Oct 17 20:37
    jeremydmiller commented #186
  • Oct 17 20:37
    jsheetzati commented #198
  • Oct 17 20:36
    jeremydmiller closed #188
  • Oct 17 20:36
    jeremydmiller commented #188
Jeremy D. Miller
@jeremydmiller
I don’t know why those two things would be related
Carl Berg
@carl-berg
I remember having that problem before with an older version ofLamar.Microsoft.DependencyInjection and the fix with IOptions solved that problem (don't remember the exact version when that got fixed)
Adding services.For<LoggerFilterOptions>().Use(c => c.GetInstance<IOptions<LoggerFilterOptions>>().Value); seems to do the trick for me
Christian Chicken
@robertfriberg_twitter
Here's what I ended up with the lookup-handler-by-request-type problem, and I ended up with a custom factory like @CodingGorilla suggested:
    [Singleton]
    public class HandlerFactory
    {
        private readonly Dictionary<Type, Type> _handlerTypeByRequestType;

        private static readonly ILog Log = LogManager.GetLogger(typeof(HandlerFactory));

        public HandlerFactory()
        {
            _handlerTypeByRequestType = Assembly
                .GetExecutingAssembly()
                .GetTypes()
                .Where(t => t.BaseType?.IsSubclassOf(typeof(Handler)) == true)
                .ToDictionary(t => t.BaseType.GetGenericArguments()[0], t => t);
        }

        public Handler GetHandlerByRequestType(Type requestType)
        {
            try
            {
                var handlerType = _handlerTypeByRequestType[requestType];
                return (Handler) IoC.GetInstance(handlerType);
            }
            catch (Exception ex)
            {
                var message = "Failed to resolve handler for type " + requestType.Name;
                Log.Error(message, ex);
                throw new NotImplementedException(message, ex);
            }
        }
    }
Jeremy D. Miller
@jeremydmiller
Any reason why you didn’t use type scanning with ConnectImplementationsToTypesClosing()?
Christian Chicken
@robertfriberg_twitter
I tried it but didn't get it to work
I did the equivalent of container.GetInstance<Handler<CoffeeRequest, CoffeeResponse>>() but with a constructed closed generic type, container.GetInstance(constructedType)
Jeremy D. Miller
@jeremydmiller
What is this for? Some kind of homegrown MediatR kind of approach?
Christian Chicken
@robertfriberg_twitter
I had to duck-duck mediatr and yes, exactly that
Jeremy D. Miller
@jeremydmiller
Blech. Won’t make you feel any better, but a huge chunk of questions here are from folks getting themselves into trouble with generics trying to roll their own MediatR or extending MediatR w/ their own middleware
Christian Chicken
@robertfriberg_twitter
Keeping it separate from the IoC bits was the best approach given my lack of knowledge of Lamar
And no trouble at all, I'm happy with the result
Christian Chicken
@robertfriberg_twitter
Ha! Bitten by the new behavior of Transient scope in Lamar. I need a single DbContext shared across all services per http request (this is NetFx 4.7 webapi)
        public DeviceMessageHandler(IAlarmService alarmService, IDeviceService deviceService, IMyDbContext context)
        {
            _alarmService = alarmService;
            _ctx = (MyDbContext) context;
            _deviceService = deviceService;

           //this is just trace/debug stuff..
            var als = (AlarmService) alarmService;
            var ds = (DeviceService) deviceService;
            var alsContextSame = Object.ReferenceEquals(als.Context,_ctx);
            var dsContextSame = Object.ReferenceEquals(ds.Context, _ctx);
            _log.Debug("alsContextSame: " + alsContextSame); //prints false
            _log.Debug("dsContextSame: " + dsContextSame);  //prints false
        }
Jeremy D. Miller
@jeremydmiller
That’s what the “Scoped” lifecycle does.
Mark Warpool
@CodingGorilla
@robertfriberg_twitter Blame Microsoft for that one :)
Christian Chicken
@robertfriberg_twitter
Dang, that was a quick response :) So I just use AddScoped() for the DbContext and all is well?
Mark Warpool
@CodingGorilla
Yea, Scoped == Transient
Jeremy D. Miller
@jeremydmiller
Not exactly, but for your purposes here, yes. Assuming that you’re resolving from the per request nested container in ASP.Net Core
Bertrand
@bertrand4_gitlab

@jeremydmiller

I don’t know why those two things would be related

Well they seem to be related somehow. Create a new webapi project for instance with dotnet new webapi. Starts the website, only log events > info are picked up. Add Lamar, all events > debug are picked up.

public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                })
                .UseLamar();
    }

Using ConfigureLogging extension methods does not help to fix this.

Also, using the AddControllers extension method in a ServiceRegistry does not seem to work. Not sure if it's tied to a Lamar issue, or just the fact that the method is called outside of the Startup class...

Svein Ellingsen
@lovmoen
FWIW: I was having similar issues with a Jasper app, using SeriLog. When I moved my .UseSeriLog() call below .UseJasper(), everything turned out nicely. I suspect that Jasper (or indeed Lamar) overwrites the log config.
Christian Chicken
@robertfriberg_twitter

Not exactly, but for your purposes here, yes. Assuming that you’re resolving from the per request nested container in ASP.Net Core

Dang, no this is .NET Framework 4.7, ASP.NET WebApi. So I guess I have t set up a scoped container for each http request then...

Jeremy D. Miller
@jeremydmiller
Ah, yeah, gotta do some setup to make that happen. It’s automatic in MVC Core — like it was in every OSS web fx before...
Jeremy D. Miller
@jeremydmiller
@bertrand4_gitlab Can you give me repro steps in a PR with a failing test?
Christian Chicken
@robertfriberg_twitter
Our controllers are thin, just one liners mapping to a single method on a single service. So not much value in doing the ControllerFactory bits. A simple Controller.Method() => GetNestedContainer().GetInstance<MyService>().Go(args); will do
Bertrand
@bertrand4_gitlab
@jeremydmiller Well it turns out the workaround for aspnet/Logging#691 does solves the problem. But I'm not sure it is still supposed to be required though. I'm currently looking for the AddControllers issue if that's what you were asking for.
Bertrand
@bertrand4_gitlab

@jeremydmiller Well it turns out the workaround for aspnet/Logging#691 does solves the problem. But I'm not sure it is still supposed to be required though. I'm currently looking for the AddControllers issue if that's what you were asking for.

Guess it is cause it is present is every HostBuilder test in LamarWithAspNetCore3 :)

Bertrand
@bertrand4_gitlab
As requested : JasperFx/lamar#189
João Miranda
@joaolongo
Hello, is there a way to configure Lamar as de default Dependency Resolver on a .Net framework Web API 2 project?
Mark Warpool
@CodingGorilla
@joaolongo Is it possible? Yes. Is there something provided with Lamar to do it for you? No.
João Miranda
@joaolongo
Is it similar to how StructureMap handled this kind of configuration?
Mark Warpool
@CodingGorilla
I have not done it, but I would assume it would be almost identical
João Miranda
@joaolongo
Nice! I will try to do it then
I wish my project specifications allowed me to use .net core haha
Jeremy D. Miller
@jeremydmiller
Basically copy/paste the supporting code for StructureMap, and replace it with Lamar equivalents. Easier in Core of course.
João Miranda
@joaolongo
@jeremydmiller I created a new project and added StructureMap support libs. From there I was able to migrate those configurations to Lamar. There are a few differences like the INestedContainer but i think I was able to work with it. Thanks!
PatrikT
@PatrikTrestik
Hi. Please help me out of problem. I couldn't find how to set which registration is default. I have dynamic number of assemblies in several project where i scan for Registry. Order of registration is not fixed. Actually last service registration is default which is not good for me.
Jeremy D. Miller
@jeremydmiller
@PatrikTrestik So, my main recommendation is “don’t do that”. You can try to use the UseIfNone functionality to not override the default. Failing that, do something that forces the assembly ordering
Christian Chicken
@robertfriberg_twitter
Can someone please confirm my assumptions regarding scopes and nested containers?
  1. Singletons are globally singleton from the root container and across all nested containers originating from the root
  2. Transients never uses the same instance twice, not even in a single graph from a single call to GetInstance
  3. Scoped - behaves like a singleton with regards to the container (root or child) it is scoped to
  4. If you never use nested containers, Scoped instances are effectively singleton
Jeremy D. Miller
@jeremydmiller
Everything is just as you say. Were the docs not clear enough? Something need to change there?
Christian Chicken
@robertfriberg_twitter
No, the docs are clear enough, and actually all the answers are right there on the lifecyle page: https://jasperfx.github.io/lamar/documentation/ioc/lifetime/
Yassine BENNANI
@yassinebennani
Hello, Please I'm currently doing a migration from structuremap to lamar, I'd like to thank you for this project, it saved my life during the migration to .net core 3
I have juste one question How can I ask lamar to call a function Func<TPluginType, TPluginType> before return a service instance ?
Jeremy D. Miller
@jeremydmiller
Lamar doesn’t yet support “activator” interception
Yassine BENNANI
@yassinebennani
Ok thank you, is there any plan to support it or no ?
Jeremy D. Miller
@jeremydmiller
Uh, there’s an issue for it for some day, but nothing concrete. Honestly, you’re the first person to ask about it
Yassine BENNANI
@yassinebennani
Thanks, I found a workaround and for my case it fit good with lamar.
Yassine BENNANI
@yassinebennani
Just for information if same one needs dynamic interception, I adapted StructureMap.DynamicInterception with a small workaround to make it works
gorillaking
@gorillaking
Does this work with Azure Functions?
Yassine BENNANI
@yassinebennani
I don't know how you register your azure function trougth Lamar but it should works with any interface registration