Windows IoC Service Architecture

I am traditionally a SQL guy. I have a ton of C # experience under my belt, but all of them are usually tools or customization projects.

Now I am entrusted with writing an application that does the following ...

  • Runs as a windows service
  • Clock for files, and when they arrive, loads them into DB
  • DB monitoring for recently uploaded files
  • Do complex parsing of these files (including aggregating db records)
  • Additional interfaces required (website for parsed query data, etc.)
  • It is necessary to support several types of files, it is necessary to support several parsers.

So this is my first foray into IoC, and I'm trying to get things right. I use Autofac and quite agree with the concepts. My problem is to understand the root of the composition when it is ok to pass the container, which I replace with my traditional concept of "factory". My application has an L2S structure and a common repository interface. I use the Autofac module to register specific types. I have a registrar and I also use a module to register specific types. In my test console application (which will be replaced by the Windows service host) I create a container and register log and dal modules, etc. Then I can enable the file browsing classes using the constructor installation to enter the registrar and repository. I also add a queue object (in my case, a queue with memory backup, but it can be a db queue), on which new files are installed (manufacturer). At the other end of the line, I need a consumer. Thus, depending on the type of file that is being called, I need to use a different loader class. I would historically use the factory pattern to return the corresponding concrete class. Since the registrar and the corresponding repository must be installed for the loader class, I don’t see how to create an instance of the corresponding loader class to process the element that leaves the queue without assigning an IoC container reference to my factory class. I know that I can implement various element handlers into my consumer class, but I say that I had 50 file types or 100, which is impractical.

After I figured out how to do this, I need to do something similar to keep track of new parsing work (entries in the db table) and process them, but I assume that it will follow the similar pattern above.

Any tips? I am so far away (a short distance) from binning my C # and go to SSIS to load a file, and then crack some kind of nasty parser code in SSIS. Please help a C # student.

+7
source share
3 answers

I realized that I could just create a new group of loader classes and put them in a dictionary and pass this to the constructor. This allows me to ask the bootloader by name.

+1
source

It seems that you are trying to construct a container for each object in your application - use DI sparingly and only where you need replaceable behavior, there is nothing wrong with the old old "new" ones, if necessary.

Another suggestion is to mark your custom file loaders with an interface, say, IFileLoader, execute all loaded assemblies and (using reflection) detect implemented loaders. Then collect all the loaders in the chain of responsibility so that if one loader cannot process the type of file in question, it transfers responsibility for the following. Thus, it will be easy to add new downloaders, and the file viewing part is clearly separated from the download part. A COR sample is optional; functionality, of course, can be provided with a simple loop.

+1
source

Here is my view on how you start as a beginner.

Start writing your classes. All dependencies on other classes are taken in the constructor.

Since you are never new to the class to get an instance at any other time than when you build your objects, this will make your program look like this:

static void Main(..) { var s1 = ...; var s2 = ...; var sn = ... SN(s1, s2, ..); sn.Wait(); } 

Now you can replace everything ... with registrations in your container. You do not use factory classes at all; IoC container is your factory. And then you replace the very root initialization:

 var sn = container.Resolve<SN>(); 

You are now using IoC. Do not use a dictionary.

+1
source

All Articles