Our application uses Autofac as an IoC container and uses automatic registration for several assemblies containing widely used code.
To reference each assembly, you can usually use Assembly.GetAssembly(typeof(<type>))it using one of the types in the corresponding assembly. This, however, is not very clear, because it is not easy to see which assembly is registered through each type, and can also lead to errors when moving types between projects.
To solve this problem, in each assembly I created an empty class with a name Types, which, of course, has an assembly namespace, so I can do automatic registration as follows:
builder.RegisterAssemblyTypes(
Assembly.GetAssembly(typeof(Xx.Common.Types)),
Assembly.GetAssembly(typeof(Xx.Core.Types)),
Assembly.GetAssembly(typeof(Xx.Infrastructure.Types)))
.AsSelf()
.AsImplementedInterfaces();
This, of course, is a "dead code" otherwise. Is it a good or smart idea to do it this way, or is it better, more idiomatic? Don't I really want to worry about it?
source
share