.net - Managing internal dependencies -


I'm having trouble finding out how to manage internal dependency by developing SDKs for me, for some reason I try to make it difficult to work with everyone.

Say I have these classes:

  class table {table (string name, IQueryProvider provider, IComObject comobject) {}} class TableFactory {table buildlet (name) & Lt; - Creates a table object}  

The problem I have for me is that the BuildTable () method must create an IQueryProvider and IComObject and pass the name down. The work I did (if I understand it correctly) has been applied to the service locator pattern, but if I use something like this:

  BuildTable (string name ) {IQueryProvider Provider = ServiceLocator.GetInstance & lt; IQueryProvider & gt; (); IComObject comobject = ServiceLocator.GetInstance & lt; IComObject & gt; (); Table tab = new table (name, provider, commbased); Return tab; }  

It now means that I should have both IQueryProvider and IComObject in the service provider that makes my dependencies difficult to see and test. That's why I created a dependency factory to create different types of items and factories in such a way:

class dependency factor {table buildtel (string name) {// to create other Buildmustels objects Call // return new table} // other build methods for things like IQueryProvider, IComObject }

Then I only have to register the dependency forefront in the locater of my service and then only call the build methods.

Do you smell this smell?

Is my first buildtable system okay, or am I worried about it.

The easy-to-use test, to provide you dependent objects, provide dependencies for the injection of factories I would like to use it I like it in a factory for all types of objects. For example, you might have a TableFactory for Tables, it will have two constructs- which causes the factories to be made immediately and another manufacturer which allows the dependent object factories to inject. Use the first in your production code, but the second in your test.

  Public category TableFactory {Personal ServiceLocator Locator {get; Set; } Public TableFactory (): this (empty) {} public TableFactory {service.locator locator} {this.Locator = locator ?? New covenants (); } Public Table Buildtel (String Name) {IQueryProvider Provider = Service Identifier.Get Instance & lt; IQueryProvider & gt; (); IComObject comobject = ServiceLocator.GetInstance & lt; IComObject & gt; (); Return new table (name, provider, comobject); }}  

You will do something with the service locator class, but inject the examples of IQueryProvider and IComObject as needed.

Note that this is a very simple type of injection. If you want, you may also have the default version of the object objects provided through the configuration file. In that case, you can only be the default constructor and you can use property injection to provide dependent objects. Properties will be marked with the ones with internal visibility so that your configuration can be created by the class factories and able to set up their property correctly. You can use internal health to make the testers available for your tests and do the same there.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -