示例#1
0
文件: LogTest.cs 项目: mehabadi/HPMS
        public void LogServiceTest()
        {
            //LocatorCreator.Execute();



            var container = new WindsorContainer();

            container.Register(Component.For <ILoggerService>().ImplementedBy <DbLoggerService>().LifeStyle.BoundTo <IService>());
            //container.Register(Component.For<ILogRepository>().ImplementedBy<LogRepository>().LifeStyle.Transient);

            container.Register(Component.For <IConnectionProvider>()
                               .UsingFactoryMethod(c => new ConnectionProvider(() =>
            {
                var s = System.Configuration.ConfigurationManager.
                        ConnectionStrings["PMSDBConnection"].ConnectionString;
                var res = new SqlConnection(s);
                res.Open();
                return(res);
            })).LifestyleBoundTo <IService>());

            DataAccessConfigHelper.ConfigureContainer <UserRepository>(container,
                                                                       () =>
            {
                var session = PMSSecuritySession.GetSession(container.Resolve <IConnectionProvider>().GetConnection());
                return(session);
            }, "PMSSecurity");

            var locator = new WindsorServiceLocator(container);

            ServiceLocator.SetLocatorProvider(() => locator);

            //var userRep = ServiceLocator.Current.GetInstance<UserRepository>();


            var uows = new MITD.Domain.Repository.UnitOfWorkScope(
                new Data.NH.NHUnitOfWorkFactory(() => PMSSecurity.Persistence.NH.PMSSecuritySession.GetSession()));



            using (var uow = new NHUnitOfWork(PMSSession.GetSession()))
                using (var uow2 = uows.CurrentUnitOfWork)
                {
                    var logFactory = new LoggerServiceFactory();
                    var logManager = new LogManagerService(logFactory);
                    var logService = new LogService(logManager);

                    var gid = Guid.NewGuid();
                    Log log = new EventLog(new LogId(gid), "diddd", LogLevel.Information, null, "clll", "mett", "ttttt", "mmmmmmm");

                    logService.AddEventLog(log.Code, log.LogLevel, null, log.ClassName, log.MethodName, log.Title, log.Messages);
                }
        }