Esempio n. 1
0
        static void TestPerf()
        {
            IDependencyProvider my    = new SimpleDependencyProvider();
            IDependencyProvider unity = new UnityDependencyContainer();

            DebugIteration("My", 100000, () => my.Resolve <Service>());
            DebugIteration("unity", 100000, () => unity.Resolve <Service>());
        }
        public void Container_WhenRegistered_ResolvesMappedType()
        {
            var container = new UnityDependencyContainer();
            container.RegisterType(typeof(BaseType), typeof(DerivedType));

            var instance = container.Resolve(typeof(BaseType));

            Assert.NotNull(instance);
            Assert.IsType<DerivedType>(instance);
        }
Esempio n. 3
0
        public static void Test()
        {
            IDependencyContainer dependencyContainer = new UnityDependencyContainer();

            dependencyContainer.Definitions
            .AddScoped <ResolveUrl>(dependencyContainer.ScopeName, new ResolveUrl(ResolveUrl));

            ResolveUrl resolveUrl = dependencyContainer.Resolve <ResolveUrl>();

            resolveUrl("~/root");
        }
Esempio n. 4
0
        public void Container_WhenRegistered_ResolvesMappedType()
        {
            var container = new UnityDependencyContainer();

            container.RegisterType(typeof(BaseType), typeof(DerivedType));

            var instance = container.Resolve(typeof(BaseType));

            Assert.NotNull(instance);
            Assert.IsType <DerivedType>(instance);
        }
Esempio n. 5
0
        private static HelloService Sequence()
        {
            IDependencyContainer dependencyContainer = new UnityDependencyContainer();

            dependencyContainer.Definitions
            .AddScoped <string>(dependencyContainer.ScopeName, "Hi")
            .AddScoped <TextWriter>(dependencyContainer.ScopeName, Console.Out);

            SequenceBootstrapper bootstrapper = new SequenceBootstrapper(task => dependencyContainer.Resolve <IBootstrapTask>(task));

            bootstrapper.Register <Sequence.WriterBootstrapTask>();
            bootstrapper.Register <Sequence.HelloBootstrapTask>();
            bootstrapper.Initialize();

            //return Engine.Environment.With<HelloService>();
            throw new NotImplementedException();
        }
Esempio n. 6
0
        public async Task InitAsync()
        {
            Container = new UnityDependencyContainer();
            Container.AddTransient <IRuntime>(this);
            Container.AddSingleton <ILogger, NullLogger>();

            var assembly = typeof(Runtime).Assembly.FullName;

            ReflectionExtensions.GetVersionIndependentName(assembly, out string extactedVersion);
            Version version;

            try
            {
                version = new Version(extactedVersion);
            }
            catch
            {
                Console.WriteLine("Failed to get RocketMod version.");
                version = new Version(0, 0, 0, 0);
            }

            Container.Activate(typeof(RegistrationByConvention));

            await Container.Resolve <ICommandProvider>().InitAsync();

            var settingsProvider = Container.Resolve <IRocketConfigurationProvider>();
            await settingsProvider.LoadAsync();

            int  p       = (int)Environment.OSVersion.Platform;
            bool isLinux = (p == 4) || (p == 6) || (p == 128);

            string mode = settingsProvider.Configuration.Logging.ConsoleMode;

            if (!mode.Equals("Compat", StringComparison.OrdinalIgnoreCase))
            {
                // use ANSI logging
                if ((isLinux && mode.Equals("Default", StringComparison.OrdinalIgnoreCase)) || mode.Equals("ANSI", StringComparison.OrdinalIgnoreCase))
                {
                    Container.AddSingleton <ILogger, AnsiConsoleLogger>("console_logger");
                }

                // use RGB logging (windows only)
                //else if (!isLinux && (mode.Equals("Default", StringComparison.OrdinalIgnoreCase) || mode.Equals("RGB", StringComparison.OrdinalIgnoreCase)))
                //    Container.RegisterSingletonType<ILogger, RgbConsoleLogger>("console_logger");
            }

            IHost impl = Container.Resolve <IHost>();

            Version = version;

            string rocketInitializeMessage = "Initializing RocketMod Runtime v" + version;

            impl.Console.WriteLine(rocketInitializeMessage, Color.DarkGreen);
            impl.Console.WriteLine(@"                                    
									
                                                           ,:
                                                         ,' |
                                                        /   :
                                                     --'   /
                                                     \/ />/
                                                     / <//_\        
                                                  __/   /           
                                                  )'-. /
                                                  ./  :\
                                                   /.' '
                                                 '/'
                                                 +
                                                '
                                              `.
                                          .-"" -
                                         (    |
                                      . .- '  '.
                                     ((.   )8:
                                 .'    / (_  )
                                  _. :(.   )8P  `
                              .  (  `-' (  `.   .
                               .  :  (   .a8a)
                              / _`(""a `a. )""'
                          ((/  .  ' )=='
                         ((    )  .8""   +
                           (`'8a.( _(   (
                        ..-. `8P) `  ) +
                      -'   (      -ab:  )
                    '    _  `    (8P""Ya
                  _((    )b -`.  ) +
                 (8)(_.aP"" _a   \( \   *
               +  ) / (8P(88))
                  (""     `""       `", Color.Cyan);


            if (!Container.IsRegistered <ILogger>("default_file_logger"))
            {
                string logsDirectory = Path.Combine(WorkingDirectory, "Logs");
                if (!Directory.Exists(logsDirectory))
                {
                    Directory.CreateDirectory(logsDirectory);
                }
                Container.AddSingleton <ILogger, FileLogger>("default_file_logger");
                FileLogger fl = (FileLogger)Container.Resolve <ILogger>("default_file_logger");
                fl.File = Path.Combine(logsDirectory, "Rocket.log");
                fl.LogInformation(rocketInitializeMessage, Color.DarkGreen);
            }

            IPermissionProvider permissions = Container.Resolve <IPermissionProvider>();

            if (!Directory.Exists(WorkingDirectory))
            {
                Directory.CreateDirectory(WorkingDirectory);
            }

            await permissions.LoadAsync(this);

            Container.Resolve <ILogger>().LogInformation($"Initializing host: {impl.Name}", Color.Green);
            await impl.InitAsync(this);
        }