/// <summary>
        /// Creates a new instance of <see cref="AuthorizationDependencies"/>.
        /// </summary>
        /// <param name="options">The options used to configure the dependencies instance.</param>
        /// <param name="handlers">The <see cref="IAuthorizationHandler"/>s used in creating an <see cref="IAuthorizationDependencies"/> object.</param>
        public static AuthorizationDependencies Create(AuthorizationOptions options, params IAuthorizationHandler[] handlers)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (handlers == null)
            {
                throw new ArgumentNullException(nameof(handlers));
            }

            var policyProvider = new DefaultAuthorizationPolicyProvider(options);
            var loggerFactory  = new DiagnosticsLoggerFactory();
            var service        = new DefaultAuthorizationService(
                policyProvider,
                handlers,
                loggerFactory.CreateDefaultLogger(),
                new DefaultAuthorizationHandlerContextFactory(),
                new DefaultAuthorizationEvaluator());

            return(new AuthorizationDependencies()
            {
                LoggerFactory = loggerFactory,
                PolicyProvider = policyProvider,
                Service = service
            });
        }
Exemple #2
0
        private void ReplaceTheDefaultLogger(IAppBuilder app)
        {
            // NOTE: This still sees Microsof.Owin as your parent switch.
            // So, Microsoft.Owin listeners on switches are still enabled.

            const string         LoggerFactoryAppKey = "server.LoggerFactory";
            SourceSwitch         sSwitch             = new SourceSwitch("Tugberk.Owin");
            ConsoleTraceListener cListener           = new ConsoleTraceListener();
            ILoggerFactory       loggerFactory       = new DiagnosticsLoggerFactory(sSwitch, cListener);

            // NOTE: One of the following ways will set the logger factory
            app.Properties[LoggerFactoryAppKey] = new TraceFactoryDelegate(name => loggerFactory.Create(name).WriteCore);
            // app.SetLoggerFactory(loggerFactory);
        }
 static LoggerFactory()
 {
     Default = new DiagnosticsLoggerFactory();
 }
 static LoggerFactory()
 {
     Default = new DiagnosticsLoggerFactory();
 }