Beispiel #1
0
        /// <summary>
        /// Creates a new instance of the Dynamic Context
        /// </summary>
        /// <returns></returns>
        public override DynamicContext Create()
        {
            if (!DependencyEngine.IsRegistered <IConfiguration>())
            {
                string stack = string.Empty;

                StackTrace stackTrace = new StackTrace();

                for (int i = 0; i < stackTrace.FrameCount; i++)
                {
                    if (stackTrace.GetFrame(i)?.GetMethod()?.ReflectedType?.FullName is string stacklevel)
                    {
                        //Check if we're running a migration from powershell
                        //We hardcore the connection string for now
                        if (stacklevel.Contains("Design.ToolingFacade+BaseRunner", StringComparison.Ordinal))
                        {
                            return(new DynamicContext(new PersistenceConnectionInfo("Data Source=.;Initial Catalog=Framework;Integrated Security=True;MultipleActiveResultSets=True")));
                        }

                        stack += stacklevel + System.Environment.NewLine;
                    }
                }

                throw new Exception(stack);
            }

            PersistenceConnectionInfo toLoad = new DependencyEngine().GetService <PersistenceConnectionInfo>();

            return(new DynamicContext(toLoad));
        }
Beispiel #2
0
        public void RegisterDependencies(IServiceRegister serviceRegister)
        {
            IEnumerable <Type> MessageHandlers = TypeFactory.GetAllImplementations(typeof(IMessageHandler));

            MessageBus.SubscribeAll(MessageHandlers);
            foreach (Type messageHandler in MessageHandlers)
            {
                //We want to register each message handler with the service provider in case
                //there are dependencies that need to be resolved in order to use it
                if (!DependencyEngine.IsRegistered(messageHandler))
                {
                    DependencyEngine.Register(messageHandler, messageHandler, typeof(TransientServiceProvider));
                }
            }
        }