@@ -45,17 +45,34 @@ private void RegisterAttributedTypes()
4545 {
4646 foreach ( var type in assembly . GetTypes ( ) )
4747 {
48+ ServiceLifetime ? lifetime = null ;
4849 if ( type . GetCustomAttributes ( typeof ( SingletonAttribute ) , false ) . Length > 0 )
4950 {
50- _serviceDescriptors . Add ( new ServiceDescriptor ( type , ServiceLifetime . Singleton ) ) ;
51+ lifetime = ServiceLifetime . Singleton ;
5152 }
5253 else if ( type . GetCustomAttributes ( typeof ( ScopedAttribute ) , false ) . Length > 0 )
5354 {
54- _serviceDescriptors . Add ( new ServiceDescriptor ( type , ServiceLifetime . Scoped ) ) ;
55+ lifetime = ServiceLifetime . Scoped ;
5556 }
5657 else if ( type . GetCustomAttributes ( typeof ( TransientAttribute ) , false ) . Length > 0 )
5758 {
58- _serviceDescriptors . Add ( new ServiceDescriptor ( type , ServiceLifetime . Transient ) ) ;
59+ lifetime = ServiceLifetime . Transient ;
60+ }
61+
62+ if ( lifetime . HasValue )
63+ {
64+ // Register the concrete type
65+ _serviceDescriptors . Add ( new ServiceDescriptor ( type , lifetime . Value ) ) ;
66+
67+ // Register all non-system interfaces implemented by this type
68+ foreach ( var iface in type . GetInterfaces ( ) )
69+ {
70+ if ( iface . Namespace ? . StartsWith ( "System" ) == false &&
71+ ! _serviceDescriptors . Any ( sd => sd . ServiceType == iface ) )
72+ {
73+ _serviceDescriptors . Add ( new ServiceDescriptor ( iface , lifetime . Value ) ) ;
74+ }
75+ }
5976 }
6077 }
6178 }
@@ -72,11 +89,7 @@ private void InitializeUsingAttribute()
7289
7390 private void BuildFactories ( )
7491 {
75- // First, sort services to resolve dependencies in the correct order
76- var sortedServices = SortServicesByDependencies ( ) ;
77-
78- // Create factories for each service
79- foreach ( var descriptor in sortedServices )
92+ foreach ( var descriptor in SortServicesByDependencies ( ) )
8093 {
8194 CreateFactory ( descriptor ) ;
8295 }
0 commit comments