예제 #1
0
 /// <summary>
 /// Constructs a new instance of the <see cref="ScopedContainer"/> class.
 /// </summary>
 /// <param name="targets">Optional.  Contains the targets that will be used as the source of registrations for the
 /// container, ultimately being passed to the <see cref="Targets"/> property.
 ///
 /// If not provided, then a new <see cref="TargetContainer"/> will be created.</param>
 /// <param name="config">Can be null.  A configuration to apply to this container (and, potentially its
 /// <see cref="Targets"/>).  If not provided, then the <see cref="Container.DefaultConfig"/> will be used</param>
 public ScopedContainer(IRootTargetContainer targets = null, IContainerConfig config = null)
     : base(targets)
 {
     // annoying: double assignment here (base already initialises it...)
     _scope = new DisposingContainerScope(this);
     (config ?? DefaultConfig).Configure(this, Targets);
 }
예제 #2
0
        public SerializerConfig()
        {
            config = new ContainerConfig();

            config.Register <IActivator>()
            .ImplementedBy(c => new ActivatorConfig().Create())
            .As <Singleton>();

            var innerScope = config.CreateScope();

            converterContainer = new ConverterContainer(innerScope);

            Match <byte>().With <Core.ByteConverter>();
            Match <sbyte>().With <SByteConverter>();
            Match <short>().With <ShortConverter>();
            Match <ushort>().With <UShortConverter>();
            Match <int>().With <Int32Converter>();
            Match <uint>().With <UInt32Converter>();
            Match <long>().With <Int64Converter>();
            Match <ulong>().With <UInt64Converter>();
            Match <string>().With <StringConverter>();
            Match <bool>().With <BoolConverter>();
            Match <float>().With <SingleConverter>();
            Match <double>().With <DoubleConverter>();
            Match <DateTime>().With <DateTimeConverter>();
            Match <Array>().With <ArrayConverter>();
            Match <IList>().With <IListConverter>();
            Match <ICollection>().With <CollectionConverter>();
            Match <IEnumerable>().With <IEnumerableConverter>();
            Match <Guid>().With <GuidConverter>();

            config             = innerScope;
            converterContainer = new ConverterContainer(config, converterContainer);
        }
        /// <summary>
        /// Creates a new instance of the <see cref="OverridingContainer"/>
        /// </summary>
        /// <param name="inner">Required.  The inner container that this one combines with.  Any dependencies not served
        /// by the new combined container's own targets will be sought from this container.  Equally, any targets in the base which
        /// are resolved when the overriding container is the root container for a resolve operation, will resolve
        /// their dependencies from this container.</param>
        /// <param name="config">Can be null.  A configuration to apply to this container (and, potentially its
        /// <see cref="Targets"/>).  If not provided, then the <see cref="Container.DefaultConfig"/> will be used</param>
        public OverridingContainer(Container inner, IContainerConfig config = null)
            : base(new OverridingTargetContainer(inner))
        {
            Inner = inner ?? throw new ArgumentNullException(nameof(inner));

            (config ?? DefaultConfig).Configure(this, Targets);
        }
예제 #4
0
 public void AddContainerConfig(IContainerConfig containerConfig)
 {
     if (containerConfig == null)
     {
         throw new ArgumentNullException(nameof(containerConfig));
     }
     _containerConfigs.Add(containerConfig);
 }
        public CommandRaiser(IContainerConfig config)
        {
            this.config = config;

            using (var container = config.Create())
            {
                commandHolder = container.Resolve <ICommandHolder>();
            }
        }
예제 #6
0
 public static IEngine Initialize(
     IContainerManager containerManager, IContainerConfig containerConfig, bool forceRecreate)
 {
     if (Singleton<IEngine>.Instance == null || forceRecreate)
     {
         var config = ConfigurationManager.GetSection("core") as Config;
         Singleton<IEngine>.Instance = CreateEngineInstance(config);
         Singleton<IEngine>.Instance.Init(containerManager, containerConfig, config);
     }
     return Singleton<IEngine>.Instance;
 }
예제 #7
0
        /// <summary>
        /// Constructs a new instance of the <see cref="Container"/> class.
        /// </summary>
        /// <param name="targets">Optional.  The target container whose registrations will be used for dependency lookup when
        /// <see cref="Resolve(ResolveContext)"/> (and other operations) is called.  If not provided, a new
        /// <see cref="TargetContainer"/> instance is constructed.  This will ultimately be available
        /// to derived types, after construction, through the <see cref="Targets"/> property.</param>
        /// <param name="config">Can be null.  Configuration to apply to this container (and, potentially its <see cref="Targets"/>).
        /// If not provided, then the <see cref="DefaultConfig"/> will be used.</param>
        /// <remarks>Note to inheritors - this constructor throws an <see cref="InvalidOperationException"/> if used by a derived class,
        /// because the application of configuration to the container will likely cause virtual methods to be called.  Instead, you
        /// should declare your own constructor with the same signature which chains instead to the <see cref="Container.Container(IRootTargetContainer)"/>
        /// protected constructor; and then you should apply the configuration yourself in that constructor (falling back to
        /// <see cref="DefaultConfig"/> if null).</remarks>
        public Container(IRootTargetContainer targets = null, IContainerConfig config = null)
            : this(targets)
        {
            if (GetType() != typeof(Container))
            {
                throw new InvalidOperationException("This constructor must not be used by derived types because applying configuration will most likely trigger calls to virtual methods on this instance.  Please use the protected constructor and apply configuration explicitly in your derived class");
            }

            _scope = new NonTrackingContainerScope(this);
            (config ?? DefaultConfig).Configure(this, Targets);
        }
예제 #8
0
        protected ApplicationConfig()
        {
            var rootConfig = new ContainerConfig();

            rootConfig.Register <ISerializerConfig>()
            .ImplementedBy(c => new SerializerConfig())
            .As <Singleton>();

            rootConfig.Register <ISerializer>()
            .ImplementedBy(c => c.Resolve <ISerializerConfig>().Create())
            .As <Singleton>();

            rootConfig.Register <IArrayPool>()
            .ImplementedBy(c => new ArrayPoolConfig().Create())
            .As <Singleton>();

            rootConfig.Register <ICompression>()
            .ImplementedBy <Compression>()
            .As <Singleton>();

            rootConfig.Register <IEncryption>()
            .ImplementedBy <Encryption>()
            .As <Singleton>();

            rootConfig.Register <IConnection>()
            .ImplementedBy <Connection>()
            .As <Transient>();

            rootConfig.Register <CommandCollection>()
            .ImplementedBy <CommandCollection>()
            .As <Singleton>();

            rootConfig.Register <HandlerCollection>()
            .ImplementedBy <HandlerCollection>()
            .As <Singleton>();

            rootConfig.Register <ICommandHolder>()
            .ImplementedBy <CommandHolder>()
            .As <Singleton>();

            rootConfig.Register <Disconnect>();
            rootConfig.Register <Connect>();
            rootConfig.Register <Error>();

            config = rootConfig.CreateScope();

            config.Register <IContainerConfig>()
            .ImplementedBy(c => config)
            .As <Singleton>();
        }
        public IContainer Bootstrap(ContainerType containerType, params IIocModule[] iocModules)
        {
            IContainerConfig container =
                ContainerHolder.Container == null
                ? new RegistrationContainerFactory().Create(containerType)
                : (IContainerConfig)ContainerHolder.Container;

            if (iocModules != null)
            {
                foreach (var iocModule in iocModules)
                {
                    iocModule.Install(container);
                }
            }

            ContainerHolder.Container = container;
            return(container);
        }
예제 #10
0
        public IAppContainer WithConfig(IContainerConfig config)
        {
            Check.NotNull(config, nameof(config), "configuration not specified");

            if (this.Registry.AllManifests != null)
            {
                throw new ContainerException("Container has already been built.");
            }

            var configType = config.GetType();

            if (_configs.ContainsKey(configType))
            {
                throw new ContainerException(
                          $"Existing configuration of type: {config.GetType()} is already configured.");
            }

            _configs[configType] = config;
            return(this);
        }
예제 #11
0
        public Connection(IContainerConfig config)
        {
            config.Register <IPacketsComposer>()
            .ImplementedBy <PacketsComposer>()
            .As <Singleton>();

            config.Register <IMessageComposer>()
            .ImplementedBy <MessageComposer>()
            .As <Singleton>();

            config.Register <ICommandRaiser>()
            .ImplementedBy <CommandRaiser>()
            .As <Singleton>();

            config.Register <ITransport>()
            .ImplementedBy <Transport>()
            .As <Singleton>();

            container = config.Create();

            receiveLoopTask = Task.Run(ReceiveLoop);
        }
        protected NodeConfig()
        {
            rootConfig.Register <ISerializer>()
            .ImplementedBy <Serializer>()
            .As <Singleton>();

            rootConfig.Register <ICompression>()
            .ImplementedBy <Compression>()
            .As <Singleton>();

            rootConfig.Register <IEncryption>()
            .ImplementedBy <Encryption>()
            .As <Singleton>();

            rootConfig.Register <IConnection>()
            .ImplementedBy <Connection>()
            .As <Transient>();

            rootConfig.Register <EventCollection>()
            .ImplementedBy <EventCollection>()
            .As <Singleton>();

            rootConfig.Register <HandlerCollection>()
            .ImplementedBy <HandlerCollection>()
            .As <Singleton>();

            rootConfig.Register <IEventHolder>()
            .ImplementedBy <EventHolder>()
            .As <Singleton>();

            rootConfig.Register <Disconnect>();
            rootConfig.Register <Error>();

            Config = rootConfig.Scope();

            Config.Register <IContainerConfig>()
            .ImplementedBy(c => Config)
            .As <Singleton>();
        }
예제 #13
0
        public Connection(IContainerConfig config)
        {
            config.Register <IPacketsComposer>()
            .ImplementedBy <PacketsComposer>()
            .As <Singleton>();

            config.Register <IMessageComposer>()
            .ImplementedBy <MessageComposer>()
            .As <Singleton>();

            config.Register <IEventRaiser>()
            .ImplementedBy <EventRaiser>()
            .As <Singleton>();

            config.Register <ICommunicator>()
            .ImplementedBy <Communicator>()
            .As <Singleton>();

            container = config.Container;

            Task.Run(async() => await ReceiveLoop());
        }
예제 #14
0
 public UseBuilder(IContainerConfig scope, ConverterContainer converters)
 {
     this.scope      = scope;
     this.converters = converters;
 }
예제 #15
0
 public static void Configure(IContainerConfig config)
 {
     ServiceLocator.SetLocatorProvider(config.Configure());
 }
 public SerializerBuilder(IContainerConfig config)
 {
     this.config = config;
 }
 public EncryptionBuilder(IContainerConfig config)
 {
     this.config = config;
 }
 public Client(IContainerConfig config)
 {
     this.config = config;
 }
예제 #19
0
 public Server(IContainerConfig config)
 {
     this.config = config;
 }
예제 #20
0
 public EventCollection(IContainerConfig config)
 {
     this.config = config;
 }
예제 #21
0
 public ClientApplication(IContainerConfig config)
 {
     this.config = config;
 }
예제 #22
0
 public CompressionBuilder(IContainerConfig config)
 {
     this.config = config;
 }
예제 #23
0
 public EventBuilder(IContainerConfig config)
 {
     this.config = config;
 }
예제 #24
0
 public EventRaiser(IContainerConfig config)
 {
     this.config = config;
 }
예제 #25
0
        /// <summary>
        /// Replaces any existing <see cref="IContainerConfig{ITargetCompiler}"/> with the passed <paramref name="configuration"/> -
        /// thus ensuring that any <see cref="Container"/> objects which are initialised with the config collection will use whichever
        /// compiler that is configured when the configuration's <see cref="IContainerConfig.Configure(Container, IRootTargetContainer)"/> method
        /// is called.
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static CombinedContainerConfig UseCompiler(this CombinedContainerConfig collection, IContainerConfig <ITargetCompiler> configuration)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(collection));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            collection.ReplaceAnyOrAdd <IContainerConfig <ITargetCompiler> >(configuration);
            return(collection);
        }
예제 #26
0
 public ConverterContainer(IContainerConfig config)
 {
     this.config = config;
     aliases     = new List <AliasDto>();
     converters  = new Dictionary <Type, ConverterDto>();
 }
예제 #27
0
 public HandlerCollection(IContainerConfig config)
 {
     this.config = config;
 }
예제 #28
0
 internal ConverterContainer(IContainerConfig config, ConverterContainer parent)
     : this(config)
 {
     this.parent = parent;
 }
 public CommandCollection(IContainerConfig config)
 {
     this.config = config;
 }
예제 #30
0
 public ConfigurationBuilder(IContainerConfig config)
 {
     this.config = config;
 }
예제 #31
0
 internal CommandBuilder(IContainerConfig config)
 {
     this.config = config;
 }