Ejemplo n.º 1
0
 private static ExceptionManager CreateExceptionManager(IConfigurationSource config)
 {
     var factory = new ExceptionPolicyFactory(config);
     var manger = factory.CreateManager();
     ExceptionPolicy.SetExceptionManager(manger);
     return manger;
 }
Ejemplo n.º 2
0
        static IUnityContainer BuildUnityContainer()
        {
            var container = new UnityContainer();
            container.LoadConfiguration();
            Logger.SetLogWriter(new LogWriterFactory().Create());

            IConfigurationSource config = ConfigurationSourceFactory.Create();
            ExceptionPolicyFactory factory = new ExceptionPolicyFactory(config);
            ExceptionManager exceptionManager = factory.CreateManager();
            ExceptionPolicy.SetExceptionManager(exceptionManager);
            return container;
        }
        public static void Configure(IUnityContainer container)
        {
            // Get Entlib config source (Current is in Web.EnterpriseLibrary.config)
            IConfigurationSource source = ConfigurationSourceFactory.Create();

            // Config container from Policy injection config settings 
            var policyInjectionSettings = (PolicyInjectionSettings)source.GetSection(PolicyInjectionSettings.SectionName);
            policyInjectionSettings.ConfigureContainer(container);

            // Config retry policy
            var retryPolicySettings = RetryPolicyConfigurationSettings.GetRetryPolicySettings(source);
            // turn off throwIfSet for unit testing
            RetryPolicyFactory.SetRetryManager(retryPolicySettings.BuildRetryManager(), throwIfSet: false);

            // get factories from config
            var policyFactory = new ExceptionPolicyFactory(source);
            var dbFactory = new DatabaseProviderFactory(source);
            var validationFactory = ConfigurationValidatorFactory.FromConfigurationSource(source);
            
            // Set default locator
            UnityServiceLocator locator = new UnityServiceLocator(container);
            ServiceLocator.SetLocatorProvider(() => locator);            
            
            container
                .AddNewExtension<Interception>()

                // register Entlib types with appropiate factory  
                .RegisterType<ExceptionManager>(new InjectionFactory(c => policyFactory.CreateManager()))
                .RegisterType<Database>(new InjectionFactory(c => dbFactory.CreateDefault()))
                .RegisterInstance<ValidatorFactory>(validationFactory)

                // use registration by convention extension for registering app types; IProfileStore, IUserRepository
                .RegisterTypes(AllClasses.FromAssemblies(Assembly.GetExecutingAssembly()), 
                               WithMappings.FromAllInterfacesInSameAssembly, 
                               WithName.Default, 
                               WithLifetime.ContainerControlled)

                // register types with interception 
                .RegisterType<AExpense.Model.User>(new Interceptor<VirtualMethodInterceptor>(),
                                                   new InterceptionBehavior<TracingBehavior>())
                .RegisterType<IExpenseRepository, ExpenseRepository>(new Interceptor<VirtualMethodInterceptor>(),
                                                                     new InterceptionBehavior<PolicyInjectionBehavior>());
        }
Ejemplo n.º 4
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            IConfigurationSource config = ConfigurationSourceFactory.Create();
            Logger.SetLogWriter(new LogWriterFactory(config).Create());
            ExceptionPolicyFactory factory = new ExceptionPolicyFactory(config);
            ExceptionPolicy.SetExceptionManager(factory.CreateManager());

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(AppDomainUnhandledException);
            try
            {
                Bootstrapper applicationBootstrapper = new Bootstrapper();
                applicationBootstrapper.Run();
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
Ejemplo n.º 5
0
 private static void DefineExceptionHandling(IConfigurationSourceBuilder builder, IConfigurationSource source)
 {
     builder.ConfigureExceptionHandling()
         .GivenPolicyWithName(Settings.Default.UnityPolicyName)
         .ForExceptionType<Exception>()
         .LogToCategory(Settings.Default.LogToCategoryNamed)
         .UsingExceptionFormatter<TextExceptionFormatter>()
         .WithSeverity(TraceEventType.Critical)
         .ThenNotifyRethrow();
     var configurationSource = CreateConfigurationSource(builder,source);
     var exceptionHandlerFactory = new ExceptionPolicyFactory(configurationSource);
     ExceptionPolicy.SetExceptionManager(exceptionHandlerFactory.CreateManager());
 }