Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 14:10
    mysticmind commented #1265
  • 10:55
    rytmis opened #67
  • Aug 21 16:48

    mysticmind on master

    When Delete and Store events on… (compare)

  • Aug 21 16:48
    mysticmind closed #1341
  • Aug 21 16:24
    mysticmind milestoned #1341
  • Aug 21 16:23
    mysticmind commented #1341
  • Aug 21 13:28
    jeremydmiller labeled #783
  • Aug 21 13:28
    jeremydmiller opened #783
  • Aug 21 06:19
    oskardudycz milestoned #1262
  • Aug 21 06:19
    oskardudycz demilestoned #1262
  • Aug 21 06:19
    oskardudycz milestoned #1283
  • Aug 21 06:19
    oskardudycz demilestoned #1283
  • Aug 21 06:18
    oskardudycz milestoned #1284
  • Aug 21 06:18
    oskardudycz demilestoned #1284
  • Aug 21 06:18
    oskardudycz milestoned #1302
  • Aug 21 06:18
    oskardudycz demilestoned #1302
  • Aug 21 06:18
    oskardudycz milestoned #1299
  • Aug 21 06:18
    oskardudycz demilestoned #1299
  • Aug 21 06:18
    oskardudycz closed #958
  • Aug 21 06:17
    oskardudycz commented #958
smchughinfo
@smchughinfo
god this is frustrating. i can't find reliable up to date easy to understand information anywhere. google is just a mess of conflicting half-information articles and lists of 23 ways to make my application awesome. i'd love to read the whole book, i really would. but far too often i find myself spending stupid amounts of time figuring out how to do things
like even when i find A way to do it i wont know if it's the right way because there's always multiple ways to do it and technology has been changing fast these last few years so most of the information you find is old and not from the same version
rant paused
smchughinfo
@smchughinfo
@CodingGorilla good link. it doesn't match up though because I don't have an ObjectFactory. which apparently is from an older version
Jeremy D. Miller
@jeremydmiller
An unlamented older version
Mark Warpool
@CodingGorilla
Sorry, just pulled that out of my archives :)
smchughinfo
@smchughinfo
YESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
@jeremydmiller had the right answer. i needed to use a "controller activator", whatever that is
Mark Warpool
@CodingGorilla
copy/paste coding is the way to go! :laughing:
Master Whiz
@whizkidwwe1217
Hi @jeremydmiller I've been using StructureMap in my ASP.NET Core projects. However, when I upgraded to ASP.NET Core 3.0, they dropped the configuration of third-party DI containers via ConfigureServices, which, returns an IServiceProvider. Now, I had to use the other way of registering the DI thru ConfigureContainer(Registry registry) void method. I'm using SaasKit library and it allows me to create child containers for multitenancy. The problem I'm facing right now is I don't know how to get the Container instance from the ConfigureContainer method. I need to get the container instance so I can call the CreateChildContainer method of the Container instance. Is there a way to access it?
Master Whiz
@whizkidwwe1217
image.png
Jeremy D. Miller
@jeremydmiller
You can register child container specific services through the Registry class
I think, it’s been years since I’ve been in that code at all.
Master Whiz
@whizkidwwe1217
Thanks @jeremydmiller I'll try that. I'm also thinking maybe it's a good idea if I just migrate to Lamar. Thanks for these awesome libraries by the way.
Jeremy D. Miller
@jeremydmiller
Yeah, except for maybe the problem where Lamar doesn’t support child containers:/
NewteqDeveloper
@NewteqDeveloper
Hi there! :) I've been tasked with upgrading our StructureMap from v3 to v4.7. Are there any breaking changes that I need to look out for?
Jeremy D. Miller
@jeremydmiller
NewteqDeveloper
@NewteqDeveloper
Thanks :thumbsup: . I have been looking at that, but I can't understand how to convert our usages of ObjectFactory to Container
Jeremy D. Miller
@jeremydmiller
Meh. ObjectFactory was just a static holder to Container
NewteqDeveloper
@NewteqDeveloper
Oh I see, I see. But how do I get the container to be passed around to my application for MVC. Because currently our project is using ObjectFactory to do bootstrapping in the application_start method, but if I understand currently since it was a wrapper, I now need to create an instance say "var container = new Container()" but how does this get passed around the application now?
NewteqDeveloper
@NewteqDeveloper
For example, there's a couple of places that use ObjectFactory.GetInstance. Can I just auto-magically replace that with an instance of IContainer that is injected into the class? Will it be automatically injected into the classes with the settings set up in the application_start method?
Jeremy D. Miller
@jeremydmiller
For a quick start, you can just write your own ObjectFactory, but it was always an anti-pattern to be calling ObjectFactory.GetInstance() in more than one or two places. If you’re an MVC app, that should only be happening in the context of a ControllerActivator, right?
NewteqDeveloper
@NewteqDeveloper
Sadly no :( I don't even know if we have a ControllerActivator. This code was written at least 10 years ago and I've been asked to upgrade to the latest structure map, but I'm struggling in understand what that exact means, cause even if I create the ObjectFactory to just house the container, it is a little difficult because we have this
ObjectFactory.Initialize(
                init =>
                {
                    init.Scan(
                        scan =>
                        {
                            scan.TheCallingAssembly();

                            scan.AssembliesFromApplicationBaseDirectory();
                            ...... /// plus more
Jeremy D. Miller
@jeremydmiller
The Action you’re passing into Initialize() would just be in new Container(Action)
NewteqDeveloper
@NewteqDeveloper
Oh, OK, I see, I see. Let me try this out. Thank you so much for the information! :slight_smile:
Jeremy D. Miller
@jeremydmiller
Good luck
NewteqDeveloper
@NewteqDeveloper
Thank you so much!
That worked :slight_smile:
cholt0425
@cholt0425

According to this page: https://structuremap.github.io/object-lifecycle/supported-lifecycles/ If I mark something as containerscoped it should dispose of that object when the container is disposed of as long as it implements IDisposable. For some reason my object's dispose method is not being called when the child container it is in is disposed.

Here is the registration:
IOCContainer.Configure(c => { c.ForConcreteType<ExporterShellView>().Configure.ContainerScoped(); c.ForConcreteType<ExportHistoryView>().Configure.ContainerScoped(); c.ForConcreteType<ExporterShellViewModel>().Configure.ContainerScoped(); c.ForConcreteType<ExportHistoryViewModel>().Configure.ContainerScoped(); });
Yet when we dispose of the container none of those objects get their Dispose method called. I confirmed that before I dispose the container if I fetch those objects and dispose of them myself that things get cleaned up properly. Any idea what might be happening?

Jeremy D. Miller
@jeremydmiller
I think you might be getting “child” container mixed up with “nested” container.
The best I can tell you at this point is to look at the SM unit tests for ContainerScoped lifecycles. And you know that SM is no longer actively supported, right?
cholt0425
@cholt0425
I thought so too but if you look at the unit tests shown in that article they specifically show nested vs child container and they both work the same with regards to disposal
I will check the unit tests checked in and see if they differ from the documentation
Jeremy D. Miller
@jeremydmiller
Okay. Nothing has changed in regards to this in years, and all the unit tests are passing. Sorry, but I’ve got nothing for you
cholt0425
@cholt0425
There is one difference between what I'm doing and the unit test. The unit test registers at the root container. I registered it in the child container
I'll see if I'm able to run the unit tests of structure map in my environment...i don't want to go on a huge side tangent here but I'll try to add a new unit test that registers the disposable in the child container as container scoped and see if it still works
Jeremy D. Miller
@jeremydmiller
Just be warned that if it doesn’t work you’re heading into “I take pull requests” territory :(
cholt0425
@cholt0425
Yup I know
cholt0425
@cholt0425
Here was my new test and it passed. I am at a complete loss..let me confirm my version vs the latest source.
[Fact]
        public void container_scoping_with_root_child_childregister_container()
        {
            var container = new Container();

            var child = container.CreateChildContainer();

            child.Configure(_ => { _.ForConcreteType<Disposable>().Configure.ContainerScoped(); });

            // Always the same object when requested from a child container
            var childDisposable = child.GetInstance<Disposable>();
            childDisposable
                .ShouldBeTheSameAs(child.GetInstance<Disposable>());

            // Same for the child container
            child.Dispose();
            childDisposable.WasDisposed.ShouldBeTrue();

            // Same for the main container
            container.Dispose();
        }
cholt0425
@cholt0425
We were on version 4.4.5. Upgraded to 4.7.1. Still doesn't work. We originally had them set as singletons and after research figured out those won't be deleted until the root container gets disposed. I thought changing them to ContainerScoped was going to be the smoking gun. Not sure where to go from here. I guess I will have to dig further. Is there anyway to "inspect" what instances the container is watching for disposal through the debugger?
Jeremy D. Miller
@jeremydmiller
Yes, but I can’t even begin to tell you how to look for that
Mark Warpool
@CodingGorilla
@cholt0425 Do you have a lot of singleton registrations? We had a situation once where we had a singleton that depended on a container scoped item, but since the dependency was created for the singleton, we always ended up getting that one instance that was used for the singleton. Was many years ago, so I don't recall the SM version or if that would still be an issue with the [more] current versions
MOHIT KUMAR AGARWAL
@m-agarwal
x.For<ICommonInterface>().Use<CommonClassA>();
x.For<ICommonInterface>().Use<CommonClassB>();
CommonClassB override the functionality of CommonClassA. I used the named parameter but it doesn't work.
I tried a lot but failed to resolved need help to resolve this.
Both dependencies are initialized in the same container.
Jeremy D. Miller
@jeremydmiller
You’re going to have to give more information than that. The last Use call wins