public void Execute() { UnityService.Get().Register <IAuthUserService, AuthUserService>() .Register <IOAuthUserService, OAuthUserService>() .Register <IAuthCookieService, AuthCookieService>(Lifestyle.Singleton) .Register <IUserService, UserService>(); }
public UnityDependencyResolver() { UnityService.Get().Container().Options.DefaultScopedLifestyle = new WebRequestLifestyle(); BootCommandProcessor.Run(); UnityService.Get().Register(typeof(IFunctionStrategyService <, ,>), typeof(FunctionStrategyService <, ,>)) .Register(typeof(IActionStrategyService <,>), typeof(ActionStrategyService <,>)) .Register <IGuestAutoMapperService, GuestAutoMapperService>() .Register <IBallroomAutoMapperService, BallroomAutoMapperService>() .Register <IExpenseAutoMapperService, ExpenseAutoMapperService>() .Register <IUndoCommandService, UndoCommandService>() .Register <IPdfAutoMapperService, PdfAutoMapperService>() .Register <ITasksAutoMapperService, TasksAutoMapperService>() .Register <ExpensesUndoStrategy>() .Register <GroupUndoStrategy>() .Register <PersonsUndoStrategy>() .Register <TaskUndoStrategy>() .Register <IEmailService, EmailService>(Lifestyle.Singleton) .Register <ITaskCardItemsService, TaskCardItemsService>() .Register(() => HttpContext.Current.GetOwinContext().Authentication, Lifestyle.Scoped) .Register <IUserStore <ApplicationUser> >(() => new UserStore <ApplicationUser>(new ApplicationDbContext()), Lifestyle.Scoped) .Register <ApplicationDbContext>(Lifestyle.Scoped) .Register <ApplicationSignInManager>(Lifestyle.Scoped) .Register <ApplicationUserManager>(Lifestyle.Scoped); UnityService.Get().Container().RegisterMvcControllers(Assembly.GetExecutingAssembly()); }
public void ConfigureAuth(IAppBuilder app) { DataProtectionProvider = app.GetDataProtectionProvider(); app.CreatePerOwinContext(() => UnityService.Get().Container().GetInstance <ApplicationUserManager>()); app.CreatePerOwinContext(() => UnityService.Get().Container().GetInstance <ApplicationSignInManager>()); // enable the application to use a cookie to store information for the signed in user // and to use a cookie to temporarily store information about a user logging in with a third party login provider // configure the sign in cookie app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login"), Provider = new CookieAuthenticationProvider { // enables the application to validate the security stamp when the user logs in. // this is a security feature which is used when you change a password or add an external login to your account. OnValidateIdentity = SecurityStampValidator.OnValidateIdentity <ApplicationUserManager, ApplicationUser>( validateInterval: TimeSpan.FromMinutes(30), regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) } }); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); AddGoogleAuth(app); AddFacebookAuth(app); AddMicrosoftAuth(app); //AddTwitterAuth(app); }
/// <summary> /// Initializes a new instance of the <see cref="SetCellValueToCommandParameterBehavior"/> class. /// </summary> public SetCellValueToCommandParameterBehavior() { try { _gridViewService = UnityService.Get().Resolve <IGridViewService>(); } catch { } }
public void Execute() { UnityService.Get().Register <IBallroomService, BallroomService>() .Register <IProcessLayoutService, ProcessLayoutService>() .Register <IProcessTableSeatsService, ProcessTableSeatsService>() .Register <ProcessTableItemStrategy>() .Register <ProcessBallroomItemStrategy>(); }
public override void Prepare() { UnityService.RegisterInstance(typeof(ICache), CacheFactory.GetLocalCache()); if (!UnityService.HasRegistered(typeof(IDbConfigLoader))) { UnityService.RegisterInstance(typeof(IDbConfigLoader), new DefaultDbConfigLoader()); } }
private IHandler <T> GetHandler <T>(object handlerTypeOrInstance) { var instance = handlerTypeOrInstance as IHandler <T>; if (instance != null) { return(instance); } return((IHandler <T>)UnityService.Resolve((Type)handlerTypeOrInstance)); }
public PlayerCharacterController(Animator animator, Rigidbody rigidbody, Transform targetTransform, UnityService unityService, PlayerHealth playerHealth, Shooter shooter) { _unityService = unityService; _playerHealth = playerHealth; _shooter = shooter; _animator = animator; _rigid = rigidbody; _transform = targetTransform; }
public IEnumerable <object> GetServices(Type serviceType) { try { return(UnityService.Get().Container().GetAllInstances(serviceType)); } catch (Exception) { return(new List <object>()); } }
public object GetService(Type serviceType) { try { return(UnityService.Get().Container().GetInstance(serviceType)); } catch (Exception) { return(null); } }
private static IUnityContainer BuildUnityContainer() { UnityService.Init(); var container = UnityService.Current; // register all your components with the container here // it is NOT necessary to register your controllers // e.g. container.RegisterType<ITestService, TestService>(); return(container); }
/// <summary> /// <see cref="System.ServiceModel.Dispatcher.IInstanceProvider"/> /// </summary> /// <param name="instanceContext"><see cref="System.ServiceModel.Dispatcher.IInstanceProvider"/></param> /// <param name="message"><see cref="System.ServiceModel.Dispatcher.IInstanceProvider"/></param> /// <returns><see cref="System.ServiceModel.Dispatcher.IInstanceProvider"/></returns> public object GetInstance(InstanceContext instanceContext, System.ServiceModel.Channels.Message message) { //This is the only call to UNITY container in the whole solution var parentInterface = _serviceType.GetInterfaces().FirstOrDefault(item => { var attrs = item.GetCustomAttributes(typeof(ServiceContractAttribute), false); return(attrs.Length > 0); }); return(UnityService.Resolve(parentInterface ?? _serviceType)); }
public void Dispose() { var container = UnityService.Get().Container(); if (container == null) { return; } container.Dispose(); }
/// <summary> /// 调用示例 /// /// </summary> /// <typeparam name="TService"></typeparam> public static void AsyncExecuteServiceAction <TService>(this TService service, string actionName, params object[] parameters) where TService : CoralService { System.Threading.Tasks.Task.Factory.StartNew(() => { using (var newservice = UnityService.Resolve <TService>()) { newservice.InitContext(service.AppContext, service.UserContext, service.SessionContext, service.PageContext); newservice.ExecuteMethod <object>(actionName, parameters); } }); }
public void CreateCookie(string userName) { var userRepository = UnityService.Get().Container().GetInstance <IUserRepository>(); // because IAuthCookieService is singleton var user = userRepository.GetUserByName(userName); var userData = user.UserKey.ToString(); var authTicket = new FormsAuthenticationTicket(1, user.Username, DateTime.Now, DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes), false, userData); var encryptedTicket = FormsAuthentication.Encrypt(authTicket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); HttpContext.Current.Response.Cookies.Add(cookie); }
public void InstallModules() { try { _modules = MetaDataManager.Type.Find(CoralModule.IsCoralModule) .SortByDependencies(item => { //所有的模块都默认依赖于CoralModule if (item == typeof(CoreModule)) { return(new List <Type>()); } var dependencies = DependencyAttribute.GetDependencies(item).Where(type => !type.IsAbstract).ToList(); dependencies.Add(typeof(CoreModule)); return(dependencies); }) .Select(item => UnityService.Resolve(item) as CoralModule) .Where(item => item != null) .ToList(); _coralModules = new Dictionary <string, CoralModule>(); _typeModules = new Dictionary <Type, CoralModule>(); //构建名字和模块的字典 foreach (var module in _modules) { if (_coralModules.ContainsKey(module.Name)) { throw CoralException.ThrowException(item => item.ModuleExisted, module.Name); } _coralModules.Add(module.Name, module); } //构建类型 foreach (var module in _modules) { foreach (var type in module.Types) { if (!_typeModules.ContainsKey(type)) { _typeModules.Add(type, module); } } } _modules.ForEach(item => item.Prepare()); _modules.ForEach(item => item.Install()); _modules.ForEach(item => item.Installed()); } catch (ReflectionTypeLoadException ex) { throw new CoralModuleException(ex); } }
/// <summary> /// Registers the specified handler type to the message dispatcher. /// </summary> /// <param name="messageDispatcher">Message dispatcher instance.</param> /// <param name="handlerType">The type to be registered.</param> private static void RegisterType(IMessageDispatcher messageDispatcher, Type handlerType) { MethodInfo methodInfo = messageDispatcher.GetType().GetMethod("Register", new[] { typeof(Type) }); var handlerIntfTypeQuery = handlerType.GetInterfaces() .Where(type => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IHandler <>)); foreach (var handlerIntfType in handlerIntfTypeQuery) { UnityService.RegisterType(handlerIntfType, handlerType); var messageType = handlerIntfType.GetGenericArguments().First(); MethodInfo genericMethodInfo = methodInfo.MakeGenericMethod(messageType); genericMethodInfo.Invoke(messageDispatcher, new object[] { handlerIntfType }); } }
static async Task MainAsync() { #if (!DEBUG) ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new UnityService() }; ServiceBase.Run(ServicesToRun); #else UnityService myServ = new UnityService(); //myServ.SetupService().ConfigureAwait(true); await myServ.BeginService(); #endif }
static void Main(string[] args) { Server server = new Server { Services = { UnityService.BindService(new UnityServiceImpl()) }, Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) } }; server.Start(); Console.WriteLine("Press any key to stop the server..."); Console.ReadKey(); server.ShutdownAsync().Wait(); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var service = UnityService.Get().Container().GetInstance <ITaskCardItemsService>(); if (Items != null) { foreach (var item in Items) { if (service.Validate(item.Type, item.Value)) { continue; } yield return(new ValidationResult(string.Format("Invalid {0} format", item.Type), new[] { item.Type })); } } }
public static void Init() { var typeRegistry = UnityService.Get().Container().GetInstance <IXmlSerializationTypeRegistry>(); IEnumerable <Type> typesThatImplementIUndoCommand = null; try { typesThatImplementIUndoCommand = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(n => n.GetTypes()) .Where(n => n.IsClass && typeof(IUndoCommand).IsAssignableFrom(n)); } catch (ReflectionTypeLoadException ex) { _logger.Error(ex.Message, ex); } foreach (var type in typesThatImplementIUndoCommand) { typeRegistry.RegisterType(type); } }
private void Awake() { unityService = UnityService.DefaultService(); }
public void Execute() { UnityService.Get().Register <IUndoRepository, UndoRepository>() .Register <IXmlSerializationTypeRegistry, XmlSerializationTypeRegistry>(Lifestyle.Singleton); }
public void Execute() { UnityService.Get().Register <IGroupRepository, GroupRepository>(Lifestyle.Scoped); }
public void Execute() { UnityService.Get().Register <IExpenseRepository, ExpenseRepository>() .Register <IBudgetRepository, BudgetRepository>(); }
public GenericsFactory() { InitStrategys(); Creator = type => (TStrategy)UnityService.Resolve(type); }
public void Execute() { UnityService.Get().Register <ITaskRepository, TaskRepository>(); }
internal static void Init() { UnityService.Get().Register <IUserRepository, UserRepository>() .Register <IOAuthWrapper, OAuthWrapper>() .Register <IMapperService, MapperService>(); }
public void Execute() { UnityService.Get().Register(typeof(IUnitOfWork <>), typeof(UnitOfWork <>), Lifestyle.Scoped); }
public void Execute() { UnityService.Get().Register <ITaskService, TaskService>(); }