Пример #1
0
        public void If_log_directory_is_undefined_use_working_directory()
        {
            var configSettings = new ConfigSettings();
            var registry       = new DependencyRegistry(configSettings);
            var container      = new Container(registry);

            var instance = container.GetInstance <ILogger>();

            Assert.IsNotNull(instance);
            Assert.IsTrue(instance is LoggerAdapter);
            Assert.AreEqual(typeof(DependencyRegistry).Namespace, instance.Name);

            // Should be 1 logfile target
            ReadOnlyCollection <Target> targets = (instance as LoggerAdapter).Factory.Configuration.AllTargets;

            Assert.AreEqual(1, targets.Count);
            FileTarget fileTarget = targets.OfType <FileTarget>().First();

            Assert.IsNotNull(fileTarget);
            Assert.AreEqual("LogFile", fileTarget.Name);

            // Path to the logfile should be the default
            string expectedLogPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "default.log");

            Assert.AreEqual(expectedLogPath, fileTarget.FileName.Render(null));
        }
        public void GetExport_IFilterableFakePartWithComposedDependencies_IsRecomposed()
        {
            var strategy   = new FilterablePluginContextStrategy(_path, FakeFilterableIds.AlphaFakeId);
            var container  = strategy.CreateContainer();
            var dependency = container.GetExport <IFilterableFakeDependency>();

            IFilterableFakePartWithComposedDependencies part = null !;

            DependencyRegistry <IFilterableFakeDependency>
            .ExecuteWhileArmed(dependency,
                               () => part = container.GetExport <IFilterableFakePartWithComposedDependencies>());

            var newDependency = container.GetExport <IFilterableFakeDependency>();

            IFilterableFakePartWithComposedDependencies newPart = null !;

            DependencyRegistry <IFilterableFakeDependency>
            .ExecuteWhileArmed(newDependency,
                               () => newPart = container.GetExport <IFilterableFakePartWithComposedDependencies>());

            Assert.NotNull(newPart);
            Assert.Equal(newDependency, newPart.Dependency);
            Assert.NotNull(part);
            Assert.NotEqual(part.Dependency, newPart.Dependency);
        }
Пример #3
0
        public void If_log_level_is_undefined_use_info_by_default()
        {
            var configSettings = new ConfigSettings();
            var registry       = new DependencyRegistry(configSettings);
            var container      = new Container(registry);

            var instance = container.GetInstance <ILogger>();

            Assert.IsNotNull(instance);
            Assert.IsTrue(instance is LoggerAdapter);
            Assert.AreEqual(typeof(DependencyRegistry).Namespace, instance.Name);

            // Should be a single rule for logging
            IList <LoggingRule> rules = (instance as LoggerAdapter).Factory.Configuration.LoggingRules;

            Assert.AreEqual(1, rules.Count);

            // Should default to logging Info and up
            LoggingRule rule = rules.First();

            Assert.IsNotNull(rule);
            Assert.IsNotNull(rule.Levels);
            Assert.AreEqual(4, rule.Levels.Count);
            Assert.AreEqual(rule.Levels[0].Ordinal, LogLevel.Info.Ordinal);
            Assert.AreEqual(rule.Levels[1].Ordinal, LogLevel.Warn.Ordinal);
            Assert.AreEqual(rule.Levels[2].Ordinal, LogLevel.Error.Ordinal);
            Assert.AreEqual(rule.Levels[3].Ordinal, LogLevel.Fatal.Ordinal);
        }
Пример #4
0
        private static int Run(ExecuteOptions options)
        {
            PopulateMissingConfigValues(ref options);
            var app = DependencyRegistry.GetApplication(options);

            return(app.Run(options));
        }
        //private XPSession

        public NetworkManagerAndroid(WifiDirectImpl wifiDirectImpl)
        {
            DependencyRegistry.AddDependency <INetworkManager>(this);
            _wifiDirectImpl = wifiDirectImpl;
            _wifiDirectImpl.ServiceFound          += OnServiceFound;
            _wifiDirectImpl.ConnectionEstablished += OnConnectionEstablished;
            _wifiDirectImpl.MessageReceived       += OnMessageReceived;
        }
Пример #6
0
        private void InstallPlatformDependencies()
        {
#if UNITY_ANDROID || UNITY_IOS
            DependencyRegistry.RegisterInterface <IVibrationServiceController, VibrationServiceController>();
#else
            DependencyRegistry.RegisterInterface <IVibrationServiceController, NullVibrationServiceController>();
#endif
        }
Пример #7
0
        private void OpenDetailPage(OpenDetailPageMessage message)
        {
            Detail = DependencyRegistry.ResolveDetailPage(message.Data);

            if (!MasterBehavior.Equals(MasterBehavior.Split) &&
                !MasterBehavior.Equals(MasterBehavior.SplitOnLandscape) &&
                !MasterBehavior.Equals(MasterBehavior.SplitOnPortrait))
            {
                IsPresented = false;
            }
        }
Пример #8
0
        public App()
        {
            InitializeComponent();

            DependencyRegistry.Init();

            //var vRealmDb = Realm.GetInstance();

            MainPage = new Starting();

            var embeddedResources = new ReflectionHelper().ListAllEmbeddedResources();
        }
        public void Ensure_that_durable_memory_repository_can_be_obtained()
        {
            var configSettings = new ConfigSettings();
            configSettings.DataDirectory = "foobar";
            var registry = new DependencyRegistry(configSettings);
            var container = new Container(registry);
            var instance = container.GetInstance<IRepository<IJsonEntity<ConfigRoot>>>();

            Assert.IsNotNull(instance);
            Assert.IsTrue(instance is DurableMemoryRepository<ConfigRoot>);

            Assert.AreEqual(configSettings.DataDirectory, (instance as DurableMemoryRepository<ConfigRoot>).Path);
        }
        private void RegisterAnalysis(CompilationStartAnalysisContext context)
        {
            DependencyRegistry dependencyRegistry;

            if (!DependencyRegistry.TryCreateRegistry(context.Compilation, out dependencyRegistry))
            {
                return;
            }

            context.RegisterSyntaxNodeAction(
                ctx => AnalyzeInvocation(ctx, dependencyRegistry),
                SyntaxKind.InvocationExpression
                );
        }
Пример #11
0
        public void Ensure_that_durable_memory_repository_can_be_obtained()
        {
            var configSettings = new ConfigSettings();

            configSettings.DataDirectory = "foobar";
            var registry  = new DependencyRegistry(configSettings);
            var container = new Container(registry);
            var instance  = container.GetInstance <IRepository <IJsonEntity <ConfigRoot> > >();

            Assert.IsNotNull(instance);
            Assert.IsTrue(instance is DurableMemoryRepository <ConfigRoot>);

            Assert.AreEqual(configSettings.DataDirectory, (instance as DurableMemoryRepository <ConfigRoot>).Path);
        }
Пример #12
0
        public void If_data_directory_is_use_working_directory_and_warn()
        {
            var configSettings = new ConfigSettings();
            var registry       = new DependencyRegistry(configSettings);
            var container      = new Container(registry);
            var instance       = container.GetInstance <IRepository <IJsonEntity <ConfigRoot> > >();

            Assert.IsNotNull(instance);
            Assert.IsTrue(instance is DurableMemoryRepository <ConfigRoot>);

            string expectedDataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "configdata");

            Assert.AreEqual(expectedDataPath, (instance as DurableMemoryRepository <ConfigRoot>).Path);
        }
Пример #13
0
        protected void Application_Start()
        {
            var builder = new ContainerBuilder();

            DependencyRegistry.RegisterAll(builder);
            builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Пример #14
0
        protected void Application_Start()
        {
            var builder = new ContainerBuilder();

            DependencyRegistry.RegisterAll(builder);
            builder.RegisterControllers(typeof(MvcApplication).Assembly);
            builder.RegisterModule(new AutofacWebTypesModule());
            var container = builder.Build();

            _containerProvider = new ContainerProvider(container);
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
        public void GetExport_IFilterableFakePartWithComposedDependencies_ReturnsPartWithDependency()
        {
            var strategy   = new FilterablePluginContextStrategy(_path, FakeFilterableIds.AlphaFakeId);
            var container  = strategy.CreateContainer();
            var dependency = container.GetExport <IFilterableFakeDependency>();

            DependencyRegistry <IFilterableFakeDependency>
            .ExecuteWhileArmed(dependency,
                               () =>
            {
                var part = container.GetExport <IFilterableFakePartWithComposedDependencies>();
                Assert.NotNull(part);
                Assert.Equal(dependency, part.Dependency);
            });
        }
Пример #16
0
        protected override void InstallDependencies()
        {
            DependencyRegistry.RegisterInterface <IGameEventManager, GameEventManager>();

            DependencyRegistry.RegisterInterface <ISceneReferenceProvider, SceneReferenceProvider>();
            DependencyRegistry.RegisterInterface <IUiDataProvider, UiDataProvider>();

            DependencyRegistry.RegisterInterface <ITimeServiceController, TimeServiceController>();
            DependencyRegistry.RegisterInterface <IInputServiceController, InputServiceController>();
            DependencyRegistry.RegisterInterface <IUiServiceController, UiServiceController>();

            InstallPlatformDependencies();

            DependencyRegistry.RegisterInterface <IAudioServiceController, AudioServiceController>();
        }
        public void GetExport_IFakePartWithComposedDependencies_ReturnsPartWithDependency()
        {
            var composedDependency = new ComposedDependency();

            DependencyRegistry <IFakeDependency>
            .ExecuteWhileArmed(composedDependency,
                               () =>
            {
                var container = _strategy.CreateContainer();
                var part      = container.GetExport <IFakePartWithComposedDependencies>();

                Assert.NotNull(part);
                Assert.Equal(composedDependency, part.Dependency);
            });
        }
Пример #18
0
        protected override void InstallDependencies()
        {
            DependencyRegistry.RegisterInterface <ILevelDataManager, LevelDataManager>();
            DependencyRegistry.RegisterInterface <IDeterministicRandomProvider, DeterministicRandomProvider>();

            DependencyRegistry.RegisterInterface <IObstacleDataManager, ObstacleDataManager>();
            DependencyRegistry.RegisterInterface <IPowerupDataManager, PowerupDataManager>();
            DependencyRegistry.RegisterInterface <IScoreDataManager, ScoreDataManager>();

            DependencyRegistry.RegisterConcreteType <BallMovement>();
            DependencyRegistry.RegisterConcreteType <ObstacleMovement>();
            DependencyRegistry.RegisterConcreteType <PowerupMovement>();
            DependencyRegistry.RegisterConcreteType <TubeMovement>();

            DependencyRegistry.RegisterInterface <ICollisionController, CollisionController>();
            DependencyRegistry.RegisterInterface <IMovementController, MovementController>();
        }
Пример #19
0
        public void Ensure_that_logger_can_be_obtained()
        {
            var configSettings = new ConfigSettings();

            configSettings.LogLevel        = LogLevel.Error.Ordinal;
            configSettings.LogFileTemplate = "foobar";

            var registry  = new DependencyRegistry(configSettings);
            var container = new Container(registry);

            var instance = container.GetInstance <ILogger>();

            Assert.IsNotNull(instance);
            Assert.IsTrue(instance is LoggerAdapter);
            Assert.AreEqual(typeof(DependencyRegistry).Namespace, instance.Name);

            // Should be 1 logfile target
            ReadOnlyCollection <Target> targets = (instance as LoggerAdapter).Factory.Configuration.AllTargets;

            Assert.AreEqual(1, targets.Count);
            FileTarget fileTarget = targets.OfType <FileTarget>().First();

            Assert.IsNotNull(fileTarget);
            Assert.AreEqual("LogFile", fileTarget.Name);

            // Path to the logfile should match config
            Assert.AreEqual(configSettings.LogFileTemplate, fileTarget.FileName.Render(null));

            // Should be a single rule for logging
            IList <LoggingRule> rules = (instance as LoggerAdapter).Factory.Configuration.LoggingRules;

            Assert.AreEqual(1, rules.Count);

            // Should use log level from config
            LoggingRule rule = rules.First();

            Assert.IsNotNull(rule);
            Assert.IsNotNull(rule.Levels);
            Assert.AreEqual(2, rule.Levels.Count);
            Assert.AreEqual(rule.Levels[0].Ordinal, LogLevel.Error.Ordinal);
            Assert.AreEqual(rule.Levels[1].Ordinal, LogLevel.Fatal.Ordinal);
        }
        private void RegisterAnalysis(CompilationStartAnalysisContext context)
        {
            DependencyRegistry dependencyRegistry;

            if (!DependencyRegistry.TryCreateRegistry(context.Compilation, out dependencyRegistry))
            {
                return;
            }

            if (!AnnotationsContext.TryCreate(context.Compilation, out AnnotationsContext annotationsContext))
            {
                return;
            }
            var immutabilityCtx = ImmutabilityContext.Create(context.Compilation, annotationsContext);

            context.RegisterSyntaxNodeAction(
                ctx => AnalyzeInvocation(ctx, immutabilityCtx, dependencyRegistry),
                SyntaxKind.InvocationExpression
                );
        }
        public void If_log_directory_is_undefined_use_working_directory()
        {
            var configSettings = new ConfigSettings();
            var registry = new DependencyRegistry(configSettings);
            var container = new Container(registry);

            var instance = container.GetInstance<ILogger>();
            Assert.IsNotNull(instance);
            Assert.IsTrue(instance is LoggerAdapter);
            Assert.AreEqual(typeof(DependencyRegistry).Namespace, instance.Name);

            // Should be 1 logfile target
            ReadOnlyCollection<Target> targets = (instance as LoggerAdapter).Factory.Configuration.AllTargets;
            Assert.AreEqual(1, targets.Count);         
            FileTarget fileTarget = targets.OfType<FileTarget>().First();
            Assert.IsNotNull(fileTarget);
            Assert.AreEqual("LogFile", fileTarget.Name);

            // Path to the logfile should be the default
            string expectedLogPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "default.log");
            Assert.AreEqual(expectedLogPath, fileTarget.FileName.Render(null));
        }
Пример #22
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(opt =>
            {
                opt.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuer   = true,
                    ValidateAudience = true,
                    ValidIssuer      = "mysite.com",
                    ValidAudience    = "mysite.com",
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("superSecretKey@3"))
                };
            });

            var builder = new ContainerBuilder();

            builder.Populate(services);
            this.ApplicationContainer = DependencyRegistry.RegisterDependencies(builder);
            return(new AutofacServiceProvider(this.ApplicationContainer));
        }
        public void GetExport_IFakePartWithComposedDependencies_IsRecomposed()
        {
            var container = _strategy.CreateContainer();

            IFakePartWithComposedDependencies part = null !;

            DependencyRegistry <IFakeDependency>
            .ExecuteWhileArmed(new ComposedDependency(),
                               () => part = container.GetExport <IFakePartWithComposedDependencies>());

            var newDependency = new ComposedDependency();

            IFakePartWithComposedDependencies newPart = null !;

            DependencyRegistry <IFakeDependency>
            .ExecuteWhileArmed(newDependency,
                               () => newPart = container.GetExport <IFakePartWithComposedDependencies>());

            Assert.NotNull(newPart);
            Assert.Equal(newDependency, newPart.Dependency);
            Assert.NotNull(part);
            Assert.NotEqual(part.Dependency, newPart.Dependency);
        }
        public void Ensure_that_logger_can_be_obtained()
        {
            var configSettings = new ConfigSettings();
            configSettings.LogLevel = LogLevel.Error.Ordinal;
            configSettings.LogFileTemplate = "foobar";

            var registry = new DependencyRegistry(configSettings);
            var container = new Container(registry);

            var instance = container.GetInstance<ILogger>();
            Assert.IsNotNull(instance);
            Assert.IsTrue(instance is LoggerAdapter);
            Assert.AreEqual(typeof(DependencyRegistry).Namespace, instance.Name);

            // Should be 1 logfile target
            ReadOnlyCollection<Target> targets = (instance as LoggerAdapter).Factory.Configuration.AllTargets;
            Assert.AreEqual(1, targets.Count);
            FileTarget fileTarget = targets.OfType<FileTarget>().First();
            Assert.IsNotNull(fileTarget);
            Assert.AreEqual("LogFile", fileTarget.Name);

            // Path to the logfile should match config
            Assert.AreEqual(configSettings.LogFileTemplate, fileTarget.FileName.Render(null));

            // Should be a single rule for logging
            IList<LoggingRule> rules = (instance as LoggerAdapter).Factory.Configuration.LoggingRules;
            Assert.AreEqual(1, rules.Count);

            // Should use log level from config
            LoggingRule rule = rules.First();
            Assert.IsNotNull(rule);
            Assert.IsNotNull(rule.Levels);
            Assert.AreEqual(2, rule.Levels.Count);
            Assert.AreEqual(rule.Levels[0].Ordinal, LogLevel.Error.Ordinal);
            Assert.AreEqual(rule.Levels[1].Ordinal, LogLevel.Fatal.Ordinal);
        }
        public void If_data_directory_is_use_working_directory_and_warn()
        {
            var configSettings = new ConfigSettings();
            var registry = new DependencyRegistry(configSettings);
            var container = new Container(registry);
            var instance = container.GetInstance<IRepository<IJsonEntity<ConfigRoot>>>();

            Assert.IsNotNull(instance);
            Assert.IsTrue(instance is DurableMemoryRepository<ConfigRoot>);

            string expectedDataPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "configdata");
            Assert.AreEqual(expectedDataPath, (instance as DurableMemoryRepository<ConfigRoot>).Path);
        }
Пример #26
0
 public WPFPresenterFactory(DependencyRegistry container)
 {
     this.container = container;
 }
Пример #27
0
 protected override void InstallDependencies()
 {
     DependencyRegistry.RegisterInterface <IPlayerLifeDataManager, PlayerLifeDataManager>();
     DependencyRegistry.RegisterInterface <ITimedInventoryDataManager, TimedInventoryDataManager>();
 }
Пример #28
0
 public MessageHandler(DependencyRegistry registry)
 {
     this.registry = registry;
 }
Пример #29
0
 public Setup()
 {
     _container = new DependencyRegistry();
 }
Пример #30
0
        static public DependencyRegistry BuildGlobalRegistry()
        {
            var registry = new DependencyRegistry
            {
                #region Resolvers

                Type <IDependencyRegistry>().Keyed(ResolverScope.Global).LinkedTo <IDependencyRegistry>(),
                Type <IDependencyRegistry>().Keyed(ResolverScope.Local).Creating(BuildLocalRegistry),

                Type <RegistryResolver>().Keyed(ResolverScope.Global).LinkedTo <RegistryResolver>(),
                Type <IDependencyResolver>().LinkedTo <RegistryResolver>(),
                Type <IDependencyResolver>().Keyed(ResolverScope.Global).LinkedTo <RegistryResolver>(),

                Type <GlyphCompositeDependencyResolver>(),
                Type <GlyphResolveContext>(),

                #endregion

                #region Composition

                Type <GlyphObject>(),

                #endregion

                #region Scheduling

                Type <InitializeScheduler>().Creating(InitializeScheduler),
                Type <LoadContentScheduler>().Creating(LoadContentScheduler),
                Type <UpdateScheduler>().Creating(UpdateScheduler).AsSingleton(),
                Type <DrawScheduler>().AsSingleton(),
                Type <RenderScheduler>(),

                Type <InitializeComponentScheduler>(),
                Type <LoadContentComponentScheduler>(),
                Type <UpdateComponentScheduler>(),

                #endregion

                #region Messaging

                Type <TrackingRouter>().AsSingleton(),
                Type <ITrackingRouter>().LinkedTo <TrackingRouter>(),
                Type <ITrackingRouter>().Keyed(ResolverScope.Global).LinkedTo <TrackingRouter>(),
                Type <ISubscribableRouter>().LinkedTo <TrackingRouter>(),
                Type <ISubscribableRouter>().Keyed(ResolverScope.Global).LinkedTo <TrackingRouter>(),
                Type <IRouter>().LinkedTo <TrackingRouter>(),
                Type <IRouter>().Keyed(ResolverScope.Global).LinkedTo <TrackingRouter>(),

                Generic(typeof(Receiver <>)),
                Generic(typeof(MessagingTracker <>)),
                Generic(typeof(MessagingSpace <>)),

                #endregion

                #region Core

                Type <SceneNode>(),
                Type <AnchoredSceneNode>(),
                Type <PositionBinding>(),

                Generic(typeof(LayerRoot <>)),
                Generic(typeof(ILayerRoot <>)).LinkedTo(typeof(LayerRoot <>)),

                Type <Camera>(),
                Type <TargetView>(),
                Type <FillView>(),
                Type <UniformFillTargetView>(),

                Type <InteractiveRoot>(),
                Type <Controls>(),

                Type <Flipper>(),

                #endregion

                #region Animation

                Type <Motion>(),
                Type <LinearMotor>(),
                Type <SteeringMotor>(),
                Type <SeekingMotor>(),
                Type <TrackMotor>(),
                Type <TimedTrajectoryMotor>(),
                Type <MeasurableTrajectoryMotor>(),
                Generic(typeof(AnimationGraph <,>)),
                Generic(typeof(AnimationPlayer <>)),

                #endregion

                #region Particles

                Type <ParticleEmitter>(),
                Type <StandardParticle>(),

                #endregion

                #region Graphics

                Type <SpriteLoader>(),
                Type <SpriteTransformer>(),
                Type <SpriteRenderer>(),

                Type <SpriteSheet>(),
                Type <SpriteSheetSplit>(),
                Type <SpriteAnimator>(),

                Type <SpriteArea>(),

                Type <RectangleSprite>(),
                Type <FilledRectangleSprite>(),
                Type <CircleSprite>(),
                Type <FilledCircleSprite>(),

                Type <FillingRectangle>(),
                Type <FillingRenderer>(),
                Type <TexturingRenderer>(),

                Type <MeshRenderer>(),
                Type <MeshesComponent>(),

                Type <EffectLoader>(),

                Generic(typeof(MappingRenderer <>)),

                #endregion

                #region Audio

                Type <SongPlayer>(),
                Type <SoundLoader>(),
                Type <SoundEmitter>(),
                Type <SoundListener>(),
                Type <SoundListenerManager>(),

                #endregion

                #region Physics

                Type <PhysicsManager>().AsSingleton(),
                Type <ColliderManager>().AsSingleton(),

                Type <RectangleCollider>(),
                Type <CircleCollider>(),
                Generic(typeof(GridCollider <>)),

                #endregion

                #region Scripting

                Type <TriggerManager>().AsSingleton(),
                Type <Trigger>(),
                Type <Actor>(),

                #endregion

                #region Input

                Type <InputSystem>().Using(InputSystem.Instance),

                #endregion

                #region Tools

                Type <FreeCamera>(),

                Type <TransformationEditor>(),
                Type <MultiModeTransformationEditor>(),
                Type <AdvancedPositionHandle>(),
                Type <AdvancedRotationHandle>(),
                Type <AdvancedScaleHandle>(),
                Type <SimplePositionHandle>(),

                Type <ShapedObjectSelector>(),

                Type <InputLogger>(),
                Type <ControlLogger>(),

                Type <EngineCursorBrushController>(),
                Type <DataCursorBrushController>(),
                Type <GridCursor>(),

                #endregion

                #region UI

                Type <InterfaceRoot>(),
                Type <UserInterface>(),

                Type <Text>(),

                Type <SimpleBorder>(),
                Type <SimpleFrame>(),
                Type <SimpleButton>(),

                Type <LinearMenu>()

                #endregion
            };

            registry.Add(Type <IDependencyRegistry>().Using(registry));
            return(registry);
        }
        public void If_log_level_is_undefined_use_info_by_default()
        {
            var configSettings = new ConfigSettings();
            var registry = new DependencyRegistry(configSettings);
            var container = new Container(registry);

            var instance = container.GetInstance<ILogger>();
            Assert.IsNotNull(instance);
            Assert.IsTrue(instance is LoggerAdapter);
            Assert.AreEqual(typeof(DependencyRegistry).Namespace, instance.Name);

            // Should be a single rule for logging
            IList<LoggingRule> rules = (instance as LoggerAdapter).Factory.Configuration.LoggingRules;
            Assert.AreEqual(1, rules.Count);

            // Should default to logging Info and up
            LoggingRule rule = rules.First();
            Assert.IsNotNull(rule);
            Assert.IsNotNull(rule.Levels);
            Assert.AreEqual(4, rule.Levels.Count);
            Assert.AreEqual(rule.Levels[0].Ordinal, LogLevel.Info.Ordinal);
            Assert.AreEqual(rule.Levels[1].Ordinal, LogLevel.Warn.Ordinal);
            Assert.AreEqual(rule.Levels[2].Ordinal, LogLevel.Error.Ordinal);
            Assert.AreEqual(rule.Levels[3].Ordinal, LogLevel.Fatal.Ordinal);
        }
Пример #32
0
 public StopEssentialServices(DependencyRegistry registry)
 {
     this.registry = registry;
 }
        private void AnalyzeInvocation(
            SyntaxNodeAnalysisContext context,
            DependencyRegistry registry
            )
        {
            var root = context.Node as InvocationExpressionSyntax;

            if (root == null)
            {
                return;
            }
            var method = context.SemanticModel.GetSymbolInfo(root).Symbol as IMethodSymbol;

            if (method == null)
            {
                return;
            }

            if (!registry.IsRegistationMethod(method))
            {
                return;
            }

            if (IsExpressionInClassInIgnoreList(root, context.SemanticModel))
            {
                return;
            }

            DependencyRegistrationExpression dependencyRegistrationExpresion;

            if (!registry.TryMapRegistrationMethod(
                    method,
                    root.ArgumentList.Arguments,
                    context.SemanticModel,
                    out dependencyRegistrationExpresion
                    ))
            {
                // this can happen where there's a new registration method
                // that we can't map to
                // so we fail
                var diagnostic = Diagnostic.Create(
                    Diagnostics.RegistrationKindUnknown,
                    root.GetLocation()
                    );
                context.ReportDiagnostic(diagnostic);
                return;
            }

            var dependencyRegistration = dependencyRegistrationExpresion.GetRegistration(
                method,
                root.ArgumentList.Arguments,
                context.SemanticModel
                );

            if (dependencyRegistration == null)
            {
                /* This can happen in the following scenarios:
                 * 1) ObjectScope is passed in as a variable and we can't extract it.
                 * 2) Some require argument is missing (compile error).
                 * We fail because we can't analyze it.
                 */
                var diagnostic = Diagnostic.Create(
                    Diagnostics.RegistrationKindUnknown,
                    root.GetLocation()
                    );
                context.ReportDiagnostic(diagnostic);
                return;
            }

            InspectRegistration(dependencyRegistration, context);
        }
        private void AnalyzeInvocation(
            SyntaxNodeAnalysisContext context,
            DependencyRegistry registry
            )
        {
            var root = context.Node as InvocationExpressionSyntax;

            if (root == null)
            {
                return;
            }
            var method = context.SemanticModel.GetSymbolInfo(root).Symbol as IMethodSymbol;

            if (method == null)
            {
                return;
            }

            if (!registry.IsRegistationMethod(method))
            {
                return;
            }

            if (IsExpressionInClassInIgnoreList(root, context.SemanticModel))
            {
                return;
            }

            DependencyRegistrationExpression dependencyRegistrationExpresion;

            if (!registry.TryMapRegistrationMethod(
                    method,
                    root.ArgumentList.Arguments,
                    context.SemanticModel,
                    out dependencyRegistrationExpresion
                    ))
            {
                // this can happen where there's a new registration method
                // that we can't map to
                // so we fail
                var diagnostic = Diagnostic.Create(
                    Diagnostics.RegistrationKindUnknown,
                    root.GetLocation()
                    );
                context.ReportDiagnostic(diagnostic);
                return;
            }

            var dependencyRegistration = dependencyRegistrationExpresion.GetRegistration(
                method,
                root.ArgumentList.Arguments,
                context.SemanticModel
                );

            if (dependencyRegistration == null)
            {
                /* This can happen in the following scenarios:
                 * 1) ObjectScope is passed in as a variable and we can't extract it.
                 * 2) Some require argument is missing (compile error).
                 * We fail because we can't analyze it.
                 */
                var diagnostic = Diagnostic.Create(
                    Diagnostics.RegistrationKindUnknown,
                    root.GetLocation()
                    );
                context.ReportDiagnostic(diagnostic);
                return;
            }

            var typesToInspect = GetTypesToInspect(dependencyRegistration);

            if (typesToInspect.Any(t => t.IsNullOrErrorType()))
            {
                // we expected a type, but didn't get one, so fail
                var diagnostic = Diagnostic.Create(
                    Diagnostics.SingletonRegistrationTypeUnknown,
                    root.GetLocation()
                    );
                context.ReportDiagnostic(diagnostic);
                return;
            }

            foreach (var typeToInspect in typesToInspect)
            {
                var isMarkedSingleton = typeToInspect.IsTypeMarkedSingleton();

                if (!isMarkedSingleton && dependencyRegistration.ObjectScope == ObjectScope.Singleton)
                {
                    var diagnostic = Diagnostic.Create(
                        Diagnostics.UnsafeSingletonRegistration,
                        root.GetLocation(),
                        typeToInspect.GetFullTypeNameWithGenericArguments()
                        );
                    context.ReportDiagnostic(diagnostic);
                }
                else if (isMarkedSingleton && dependencyRegistration.ObjectScope != ObjectScope.Singleton)
                {
                    var diagnostic = Diagnostic.Create(
                        Diagnostics.AttributeRegistrationMismatch,
                        root.GetLocation(),
                        typeToInspect.GetFullTypeNameWithGenericArguments()
                        );
                    context.ReportDiagnostic(diagnostic);
                }
            }
        }
Пример #35
0
 private void OnApplicationQuit()
 {
     DependencyRegistry.Reset();
 }
Пример #36
0
 public InMemoryServiceBus(DependencyRegistry registry)
 {
     this.registry = registry;
 }