Exemplo n.º 1
0
        /// <summary>
        /// Инициализировать модуль.
        /// </summary>
        /// <param name="provider">Провайдер модулей.</param>
        public async ValueTask <Nothing> InitializeModule(IModuleProvider provider)
        {
            if (Interlocked.Exchange(ref _isInitialized, 1) == 0)
            {
                Interlocked.Exchange(ref _parent, provider);
                if (_callbacks != null)
                {
                    await _callbacks.OnInitilizeLifetimeCallback(provider);

                    Interlocked.Exchange(ref _isDoneInitialize, 1);
                }
                if (_attachToParentDispose)
                {
                    var lt = provider?.QueryView <ModuleInterface.IModuleLifetimeEvents>();
                    if (lt != null)
                    {
                        Interlocked.Exchange(ref _isDisposeAttached, 1);
                        lt.Disposed       += ParentOnDisposed;
                        lt.AllInitialized += ParentOnAllInitialized;
                        lt.Suspended      += ParentOnSuspended;
                        lt.Resumed        += ParentOnResumed;
                        lt.AllResumed     += ParentOnAllResumed;
                    }
                }
            }
            return(Nothing.Value);
        }