Sorry for this long question, it is labeled wiki, as I am asking for something that may not have a very specific answer. If it is closed, so be it.
My main question is:
How would you write a free interface that is not completely defined in the base classes, so that programs that use free interfaces can refer to new words within the existing structure and maintain a supportive interface so that after the dot, intellisense only lists the keywords that actually apply at this point.
At the third iteration, I rewrite my IoC container. The second iteration was to improve performance; this third iteration would be to solve some extensibility and separation problems.
The main problem with extensibility is that it does not exist. Recently, I wanted to use a service that had a lifetime, and after the expiration of its service life, allow a new copy. For example, read the configuration file every minute, but not more often. This was not supported by my current IoC solution, but the only way to add it is to go into the base class library and add support there. This means that I was unable to create an extensible class library. In fairness, I was not going to build extensibility into it, but then I did not fully understand how much pain it would be for this, and add something like that later.
I look at my free interface for customization, and since I also want to expand the extensibility in the interface (or get rid of it, which I don't want to do), I need to do something differently.
As such, I need your opinion. I have very little experience actually using free interfaces, but I have seen quite a lot of code that uses them, and as such there is one obvious advantage right out of the box:
- Code that uses free interfaces is usually very easy to read.
In other words, it is:
ServiceContainer.Register<ISomeService>() .From.ConcreteType<SomeService>() .For.Policy("DEBUG") .With.Scope.Container() .And.With.Parameters .Add<String>("connectionString", "Provider=....") .Add<Boolean>("optimizeSql", true);
easier to read than this:
ServiceContainer.Register(typeof(ISomeService), typeof(SomeService), "DEBUG", ServiceScope.Container, new Object[] { "Provider=...", true });
This readability is one of the problems.
However, a programmer’s guide is something else that isn’t easy to understand when reading existing code, online or in an editor.
Basically, when I type this:
ServiceContainer.Register<ISomeService>() .From.| ^-cursor here
and then intellisense will show the available permission types. After I selected this one and write:
ServiceContainer.Register<ISomeService>() .From.ConcreteType<SomeService>() .For.|
then I get access only after the keyword "For", for example, "Politics", etc.
However, is this a big problem? Do you have any free interfaces you used? An obvious coincidence for defining an interface is to make a class or interface with all keywords and everything so that intellisense contains everything after each comma, but this could also lead to it being legal (like compiling, for example):
ServiceContainer.Register<ISomeService>() .From.ConcreteType<SomeService>() .From.Delegate(() => new SomeService()) .From.With.For.Policy("Test");
therefore, I would like to structure the free interfaces so that after you have specified how to enable the service, you cannot do it again.
- In other words, smooth interfaces are very easy to use, as they direct you to what you can do.
But is this typical? Since I want to be able to add a bunch of these keywords, such as resolver type (ConcreteType, Delegate, etc.), Region type (Factory, container, Singleton, Cache, etc.) as extension methods, so programs can define their own ways of doing this without inserting or modifying the base classes, which means that I will need to provide interfaces for all intermediate stops and allow relevant important keywords. The implementation for these keywords should then select one intermediate-stop interface to return, if necessary.
So it looks like I need to define an interface for:
- xyz.From.
xyz.From.<Resolver here>.<Resolver here>.With.<Resolver here>.For.
etc .. but it looks fragmented for me.
Can someone who has experience with current interfaces go back and read my quoted answer at the top of the screen and try to give me a short answer?