Exemple #1
0
        protected override void ConfigureContainer()
        {
            //base.RegisterDefaultTypesIfMissing();
            ContainerExtension.RegisterInstance <ILoggerFacade>(Logger);

            ContainerExtension.RegisterInstance(this.ModuleCatalog);
        }
        /// <summary>
        /// <see cref="M:Microsoft.Practices.Unity.LifetimeManager.GetValue"/>
        /// </summary>
        /// <returns><see cref="M:Microsoft.Practices.Unity.LifetimeManager.GetValue"/></returns>
        public override object GetValue()
        {
            object result = null;

            //Get object depending on  execution environment ( WCF without HttpContext,HttpContext or CallContext)

            if (OperationContext.Current != null)
            {
                //WCF without HttpContext environment
                ContainerExtension containerExtension = OperationContext.Current.Extensions.Find <ContainerExtension>();
                if (containerExtension != null)
                {
                    result = containerExtension.Value;
                }
            }
            else if (HttpContext.Current != null)
            {
                //HttpContext avaiable ( ASP.NET ..)
                if (HttpContext.Current.Items[_key.ToString()] != null)
                {
                    result = HttpContext.Current.Items[_key.ToString()];
                }
            }
            else
            {
                //Not in WCF or ASP.NET Environment, UnitTesting, WinForms, WPF etc.
                result = CallContext.GetData(_key.ToString());
            }


            return(result);
        }
Exemple #3
0
        protected override IContainerExtension CreateContainerExtension()
        {
            var container = new ContainerExtension(new NInjectContainer());

            LoadModule(container.Instance);
            return(container);
        }
        private void RegisterExtension(string assemblyName, string className)
        {
            Assembly           asm        = Load(assemblyName);
            ContainerExtension extensions = (ContainerExtension)asm.CreateInstance(className);

            _Container.AddExtension(extensions);
        }
Exemple #5
0
        public override void SetValue(object newValue)
        {
            if (OperationContext.Current != null)
            {
                var containerExtension = OperationContext.Current.Extensions.Find <ContainerExtension>();
                if (containerExtension == null)
                {
                    containerExtension = new ContainerExtension()
                    {
                        Value = newValue
                    };

                    OperationContext.Current.Extensions.Add(containerExtension);
                }
            }
            else if (HttpContext.Current != null)
            {
                if (HttpContext.Current.Items[_key.ToString()] == null)
                {
                    HttpContext.Current.Items[_key.ToString()] = newValue;
                }
            }
            else
            {
                if (AppDomain.CurrentDomain.IsFullyTrusted)
                {
                    CallContext.SetData(_key.ToString(), newValue);
                }
            }
        }
 /// <summary>
 /// <see cref="M:Microsoft.Practices.Unity.LifetimeManager.RemoveValue"/>
 /// </summary>
 public override void RemoveValue()
 {
     if (OperationContext.Current != null)
     {
         //WCF without HttpContext environment
         ContainerExtension containerExtension = OperationContext.Current.Extensions.Find <ContainerExtension>();
         if (containerExtension != null)
         {
             OperationContext.Current.Extensions.Remove(containerExtension);
         }
     }
     else if (HttpContext.Current != null)
     {
         //HttpContext avaiable ( ASP.NET ..)
         if (HttpContext.Current.Items[_key.ToString()] != null)
         {
             HttpContext.Current.Items[_key.ToString()] = null;
         }
     }
     else
     {
         //Not in WCF or ASP.NET Environment, UnitTesting, WinForms, WPF etc.
         CallContext.FreeNamedDataSlot(_key.ToString());
     }
 }
        /// <summary>
        /// <see cref="LifetimeManager.SetValue"/>
        /// </summary>
        /// <param name="newValue"><see cref="LifetimeManager.SetValue"/></param>
        public override void SetValue(object newValue)
        {
            if (OperationContext.Current != null)
            {
                //WCF without HttpContext environment
                ContainerExtension containerExtension = OperationContext.Current.Extensions.Find <ContainerExtension>();
                if (containerExtension == null)
                {
                    containerExtension = new ContainerExtension
                    {
                        Value = newValue
                    };

                    OperationContext.Current.Extensions.Add(containerExtension);
                }
            }
            else if (HttpContext.Current != null)
            {
                //HttpContext avaiable ( ASP.NET ..)
                if (HttpContext.Current.Items[_key.ToString()] == null)
                {
                    HttpContext.Current.Items[_key.ToString()] = newValue;
                }
            }
            else
            {
                //Not in WCF or ASP.NET Environment, UnitTesting, WinForms, WPF etc.
                CallContext.SetData(_key.ToString(), newValue);
            }
        }
Exemple #8
0
 public void ReleaseObject()
 {
     if (OperationContext.Current != null)
     {
         //WCF without HttpContext environment
         ContainerExtension containerExtension = OperationContext.Current.Extensions.Find <ContainerExtension>();
         if (containerExtension != null)
         {
             object obj = containerExtension.Value;
             if (obj is IDisposable)
             {
                 (obj as IDisposable).Dispose();
             }
             OperationContext.Current.Extensions.Remove(containerExtension);
         }
     }
     else if (HttpContext.Current != null)
     {
         //HttpContext avaiable ( ASP.NET ..)
         if (HttpContext.Current.Items[key] != null)
         {
             if (HttpContext.Current.Items[key] is IDisposable)
             {
                 ((IDisposable)HttpContext.Current.Items[key]).Dispose();
             }
             HttpContext.Current.Items[key] = null;
         }
     }
     else
     {
         //Not in WCF or ASP.NET Environment, UnitTesting, WinForms, WPF etc.
         CallContext.FreeNamedDataSlot(key);
     }
 }
        public App(Action <ServiceCollection> configure)
        {
            InitializeComponent();

            Device.SetFlags(new[] { "SwipeView_Experimental",
                                    "Shell_UWP_Experimental" });
            Barrel.ApplicationId = "WeeklyXamarin";

            Container.Instance.ServiceProvider
                = ContainerExtension.ConfigureServices(configure);


            //MainPage = new ContentPage
            //{
            //    Content = new StackLayout
            //    {
            //        Children =
            //        {
            //            new Label
            //            {
            //                Text = "HELLLOOOOOO",
            //                VerticalOptions = LayoutOptions.CenterAndExpand,
            //                HorizontalOptions = LayoutOptions.Center
            //            }
            //        }
            //    }
            //};

            MainPage = new AppShell();
        }
 public void OnLoaded(object sender, RoutedEventArgs e)
 {
     RegionManager.AddToRegion("StatusBarRegion", ContainerExtension.Resolve <StatusBarView>());
     RegionManager.AddToRegion("FileListRegion", ContainerExtension.Resolve <FileListView>());
     RegionManager.AddToRegion("ToolTabRegion", ContainerExtension.Resolve <ToolTabView>());
     RegionManager.AddToRegion("SettingsTabRegion", ContainerExtension.Resolve <SettingsTabView>());
     RegionManager.AddToRegion("OthersTabRegion", ContainerExtension.Resolve <OthersTabView>());
 }
Exemple #11
0
        public static object GetCurrent()
        {
            var extension = GetContainerExtension();

            if (extension == null)
            {
                extension = new ContainerExtension(DependencyResolver.Current.CreateOperationContainer());
                OperationContext.Current.Extensions.Add(extension);
            }
            return(extension.Container);
        }
Exemple #12
0
        public App(Action <ServiceCollection> configure)
        {
            InitializeComponent();

            Barrel.ApplicationId = "WeeklyXamarin";

            Container.Instance.ServiceProvider
                = ContainerExtension.ConfigureServices(configure);

            MainPage = new AppShell();
        }
Exemple #13
0
        public static void ConfigureDependencies(IServiceCollection services, IConfiguration configuration, string connectionString)
        {
            services.AddHttpContextAccessor();

            services.AddScoped <ICurrentContextProvider, CurrentContextProvider>();

            services.AddSingleton <JwtManager>();

            ContainerExtension.Initialize(services, configuration, connectionString);

            services.AddTransient <IAuthenticationService, AuthenticationService <User> >();
        }
Exemple #14
0
        public void ShouldThrowExceptionWhenNullContainerPassed()
        {
            // Arrange
            var container = default(Container);

#pragma warning disable CS8604 // Possible null reference argument.
            Action action = () => ContainerExtension.AddFluentValidation(container, _ => { });
#pragma warning restore CS8604 // Possible null reference argument.

            // Act & Assert
            action.Should().Throw <ArgumentNullException>();
        }
Exemple #15
0
        public App(Action <ServiceCollection> configure)
        {
            InitializeComponent();

            Xamarin.Forms.Device.SetFlags(new[] { "SwipeView_Experimental",
                                                  "Shell_UWP_Experimental" });
            Barrel.ApplicationId = "WeeklyXamarin";

            Container.Instance.ServiceProvider
                = ContainerExtension.ConfigureServices(configure);

            preferences = Container.Instance.ServiceProvider.GetRequiredService <IPreferences>();


            MainPage = new AppShell();
        }
Exemple #16
0
        private void ShowDialogInternal(string name, IDialogParameters parameters, Action <IDialogResult> callback)
        {
            var content = ContainerExtension.Resolve <object>(name);

            var dialogContent = content as FrameworkElement ?? throw new NullReferenceException("A dialog's content must be a FrameworkElement");
            var viewModel     = dialogContent.DataContext as IDialogAware ?? throw new NullReferenceException("A dialog's ViewModel must be IDialogAware");

            MvvmHelpers.ViewAndViewModelAction <IDialogAware>(viewModel, d => d.OnDialogOpened(parameters));

            var host = CustomHost.Host
                       ?? throw new NullReferenceException("Dialog host must be specified in the ICustomDialogHost");

            // Lazy show
            host.IsOpen        = true;
            host.DialogContent = dialogContent;

            viewModel.RequestClose += r =>
            {
                host.IsOpen = false;
                callback?.Invoke(r);
                host.DialogContent = null;
            };
        }
Exemple #17
0
 public void OnLoaded(object sender, RoutedEventArgs e)
 {
     RegionManager.AddToRegion("MainRegion", ContainerExtension.Resolve <MainView>());
 }
Exemple #18
0
 public static void ConfigureDependencies(IServiceCollection services, string connectionString)
 {
     ContainerExtension.Initialize(services, connectionString);
 }
Exemple #19
0
 public void OnLoaded(object sender, RoutedEventArgs e)
 {
     RegionManager.AddToRegion("OperandRegion", ContainerExtension.Resolve <OperandView>());
     RegionManager.AddToRegion("AnswerRegion", ContainerExtension.Resolve <AnswerView>());
 }
Exemple #20
0
        public void OnLoaded(object sender, RoutedEventArgs e)
        {
            RegionManager.AddToRegion("MainRegion", ContainerExtension.Resolve <MonsterEncountView>());

            RegionManager.RequestNavigate("MainRegion", nameof(MonsterEncountView));
        }
Exemple #21
0
        public static void ConfigureDependencies(IServiceCollection services, IConfiguration configuration, string connectionString = null)
        {
            services.AddHttpContextAccessor();

            ContainerExtension.Initialize(services, configuration, connectionString);
        }