There seem to be two questions here:
- Is it a smell code / anti primitive input pattern?
- Should there be some type to create usernames and passwords?
These are completely different problems. First, addiction is addiction. This may be complex or primitive, but dependency management must be consistent. If you use an IoC container, this is absolutely not a code smell for entering primitives. The IoC container and root composition are preferred parts of code that understands the needs of all services and how to satisfy them. Conceptually, this is done for complex and primitive types. In practice, however, there are various mechanisms for registering complex dependencies against primitive dependencies. The approach with the name of the argument you specified is fully valid. Other approaches depend on the index of the argument. The choice between them is to split the hairs, but it comes down to whether you want freedom to rename the constructor arguments or give the constructor arguments without changing the connection code.
An alternative is the presence of specific dependencies (or, even worse, the Locator pattern), which is a slippery slope towards an illegible ball of dirt.
Secondly, whether to combine two strings into a type depends on how often these values ββare used together and how DRY you want to be. At some point, a decrease in drying efficiency is observed. In addition, if values ββare always entered together, you can simply reformulate the Ninject configuration calls. No matter what you choose, make sure the rationale matches the code base.
The last point that uses IoC containers to manage objects is considered code smell. Entities are usually responsible for maintaining domain invariants when performing domain actions. (Not sure if the context / intent of the example code snippet cannot provide an alternative.)
G-wiz
source share