Esempio n. 1
0
        public static Type[] GetInterfacesCloseOf(this Type @this, Type closeType)
        {
            if (@this.IsInterface)
            {
                MiniException.UnExpectedOperated(typeof(TypeExtensions), $"{@this.FullName} isn't close of {closeType.FullName}");
            }

            return(@this.GetInterfaces()
                   .Where(t => t.IsGenericTypeDefinedBy(closeType))
                   .ToArray());
        }
Esempio n. 2
0
        public IRegistrationBuilder <TLimit> As(Type service)
        {
            if (!service.IsAssignableFrom(DefaultType))
            {
                MiniException.UnExpectedOperated(typeof(RegistrationBuilder <>), $"register type must assign from {DefaultType.FullName}");
            }

            RegistrationData.AddServices(new TypedService(service));

            return(this);
        }
Esempio n. 3
0
        public MiniContainer Build()
        {
            if (_isBuild)
            {
                MiniException.UnExpectedOperatedArgument(typeof(MiniContainerBuilder),
                                                         nameof(_isBuild), _isBuild.ToString(), "false");
            }

            var container = CreateContainer();

            Configure(container.ComponentRegistry);

            _isBuild = true;

            return(container);
        }
Esempio n. 4
0
        internal MiniContainer()
        {
            ComponentRegistry = new ComponentRegistry();

            ComponentRegistry.Register(new ComponentRegistration(
                                           LifetimeScope.SelfScopeId,
                                           new DelegateActivator(typeof(LifetimeScope), c => throw
                                                                 MiniException.UnExpectedOperated(
                                                                     typeof(MiniContainer),
                                                                     $"root can't resolve {typeof(ILifetimeScope).FullName}, {typeof(IComponentContext)}")),
                                           new CurrentLifetimeScope(),
                                           InstanceSharing.Shared,
                                           new TypedService(typeof(ILifetimeScope)),
                                           new TypedService(typeof(IComponentContext)
                                                            )));

            RootLifetimeScope = new LifetimeScope(ComponentRegistry);
        }
Esempio n. 5
0
 public ISharingLifetimeScope FindScope(ISharingLifetimeScope scope)
 => scope ?? throw MiniException.ArgumentNull(typeof(ISharingLifetimeScope));