Your leaking thatched hut during the restoration of a pre-Enlightenment state.

 

Hello, my name is Judas Gutenberg and this is my blaag (pronounced as you would the vomit noise "hyroop-bleuach").



links

decay & ruin
Biosphere II
Chernobyl
dead malls
Detroit
Irving housing

got that wrong
Paleofuture.com

appropriate tech
Arduino μcontrollers
Backwoods Home
Fractal antenna

fun social media stuff


Like asecular.com
(nobody does!)

Like my brownhouse:
   none of this stuff is actually magic
Monday, May 17 2021
In the remote workplace I've been working at getting a data migrator to migrate another, different database, and this has caused me to wade into the C# code with all its abstraction, dependency injection, and all the other forms of indirection that makes me think maybe I don't know that much about software development. I'm good at programming in a straightforward, procedural manner, and more recently I've gotten pretty good at asynchronous programming. But the things going on in this code seemed purpose-built (by, in this case, the Ukranian outsourcers) to frustrate anyone trying to understand how it worked. There were, I discovered, a whole folder full of child classes for individual entity migrations, and none of these classes were explicitly mentioned in any other code. How did the core of the program know to transfer execution threads to these classes? For a couple hours there, the code had me feeling despondent, like I would never figure it out. (I have this feeling every now and then and it's nothing new, though in recent years this feeling has been tempered by my experience that, because none of this stuff is actually magic, it is possible to figure out, and I have always been able to do that.)
So I took a break and painted more of the laboratory floor. There was a part of it that had never been painted just to the right of my computer desk in the laboratory's northeast corner (where I spend most of my time looking at screens and using a keyboard attached to Woodchuck). This part had been beneath a carpet fragment on which had set several desktop computers, none of which I'd used in years. I'd gotten rid of two of those tower computers in recent months as part of the laboratory cleanup, and there was now only one. Fortunately, it was no longer cabled to anything and actually sat on casters, so I could just roll it away and remove the carpet fragment. Interestingly, in doing this, I revealed a patch of floor that had swatchs of several different shades of dark blue from all the generations of that color I'd applied over the last 18 years. It was kind of a shame to cover up that history with fresh new paint, but that's the nature of the project. In this case, though, I thought to take a picture. The new paint included a new large white blob attached to the mass of white under the carpet directly in front of Woodchuck.


Several versions of the dark blue along with adjacent bare OSB. The wood is the new Woodchuck desk I'd built back in January.
You can see the support column the rises up to meet the base of the southest corner pillar of the solar deck at the roof.


New colors after I'd peeled the carpet out of the way and painted.

After that, I returned to Visual Studio and doggedly pursued the question of: how does the program know how to load this unnamed child classes? Eventually I found the answer (here with the comments I wrote):
 
 
 
        private static IServiceCollection AddMigrations(this IServiceCollection services, Assembly assembly)
        {
            var types = assembly
                .GetTypes()
                .Where(x => x.BaseType != null && !x.IsAbstract && x.GetInterfaces().Any(y => y == typeof(IMigration)));
            //Console.WriteLine("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
            //these are all the migration types such as XxxxxxYyyyyyZzzzzzzMigration, somehow gotten from types without hardcoding
            //thus preventing any explicit connection between the migrations and this thing making them available
            foreach (var type in types)
            {
                //Console.WriteLine(type.ToString());
                services.AddScoped(typeof(IMigration), type);
            }
            //Console.WriteLine("++FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
            return services;
        }
 
 
Evidently there are "types" in the "assembly" (directories in the source?) that can be iterated through and have their scope added to the services. I'm still hazy on how this actually works, but this code somehow does it. Having cracked that nut, I could finally go to bed.


For linking purposes this article's URL is:
http://asecular.com/blog.php?210517

feedback
previous | next