Exemple #1
0
        //NOTE: You want to hit this piece of code only once.
        static DefaultMvcApplication()
        {
            //TODO: Specify your own service locator here.
            var container = CreateContainer();

            ServiceLocatorManager.SetLocatorProvider(() => new StructureMapServiceLocator(container));
        }
        static MvcApplication()
        {
            DatabaseFactory.SetConnectionName("Mongo");

            var container = new UnityContainer();

            ServiceLocatorManager.SetLocatorProvider(() => new UnityServiceLocator(container));

            var simpleCqrsRuntime = new SimpleCqrsRuntime(container);

            simpleCqrsRuntime.Start();

            simpleCqrsRuntime.ServiceLocator.Register <IEventStore>(
                new SqlServerEventStore(
                    new SqlServerConfiguration(ConfigurationManager.ConnectionStrings["Bennington.ContentTree.Domain.ConnectionString"].ToString()),
                    new JsonDomainEventSerializer()));

            container.RegisterInstance(simpleCqrsRuntime.ServiceLocator.Resolve <ICommandBus>());
            container.RegisterInstance <SimpleCqrs.IServiceLocator>(simpleCqrsRuntime.ServiceLocator);

            Configurer.Configure
            .Content()
            .UseSql("Bennington.ContentTree.Domain.ConnectionString")
            .Run();
        }
        public MvcApplication()
        {
            var locator = new UnityServiceLocator();

            locator.Register <IServiceLocator>(locator);
            ServiceLocatorManager.SetLocatorProvider(() => locator);
        }
Exemple #4
0
        static MvcApplication()
        {
            // Register the IoC that you want Mvc Turbine to use!
            // Everything else is wired automatically

            ServiceLocatorManager.SetLocatorProvider(() => new UnityServiceLocator());
        }
Exemple #5
0
 void ISetupDescriptor.RegisterWithServiceLocator <T>(Lazy <TIService> service, Lazy <IServiceLocator> locator, string name)
 {
     if (service == null)
     {
         throw new ArgumentNullException("service");
     }
     if (locator == null)
     {
         throw new ArgumentNullException("locator", "Unable to locate ServiceLocator, please ensure this is defined first.");
     }
     if (!locator.IsValueCreated)
     {
         var descriptor = ServiceLocatorManager.GetSetupDescriptor(locator);
         if (descriptor == null)
         {
             throw new NullReferenceException();
         }
         descriptor.Do(l => RegisterInstance <T>((T)service.Value, l, name));
     }
     else
     {
         var descriptor = GetSetupDescriptorProtected(service, null);
         if (descriptor == null)
         {
             throw new NullReferenceException();
         }
         descriptor.Do(l => RegisterInstance <T>((T)service.Value, locator.Value, name));
     }
 }
Exemple #6
0
        public void CreateMonoServiceAndResolveIt()
        {
            ServiceLocatorManager.Register <IMockInterface>(ServiceLocatorManager.AsMono <MonoMockServiceFeature>());

            IMockInterface service = ServiceLocatorManager.Resolve <IMockInterface>();

            Assert.IsInstanceOf(typeof(MonoMockServiceFeature), service);
        }
Exemple #7
0
        static MvcApplication()
        {
            // Register the IoC that you want Mvc Turbine to use!
            // Everything else is wired automatically

            // For now, let's use the Unity IoC
            ServiceLocatorManager.SetLocatorProvider(() => new NinjectServiceLocator());
        }
 public MvcApplication()
 {
     ServiceLocatorManager.SetLocatorProvider(() => new HiroServiceLocator());
     //ServiceLocatorManager.SetLocatorProvider(() => new StructureMapServiceLocator());
     //ServiceLocatorManager.SetLocatorProvider(() => new UnityServiceLocator());
     //ServiceLocatorManager.SetLocatorProvider(() => new WindsorServiceLocator());
     //ServiceLocatorManager.SetLocatorProvider(() => new NinjectServiceLocator());
 }
Exemple #9
0
        //NOTE: You want to hit this piece of code only once.
        static DefaultMvcApplication()
        {
            // Initialize the Ninject Kernel
            IKernel kernel = InitializeNinject();

            // Tell the MVC Turbine runtime to use the initialized kernel
            ServiceLocatorManager.SetLocatorProvider(() => new NinjectServiceLocator(kernel));
        }
Exemple #10
0
        public void Empty_Provider_Return_Null_Provider()
        {
            ServiceLocatorManager.SetLocatorProvider(() => null);

            IServiceLocator locator = ServiceLocatorManager.Current;

            Assert.IsNull(locator);
        }
Exemple #11
0
        public void CreateNonMonoServiceAndResolveIt()
        {
            ServiceLocatorManager.Register <IMockInterface>(new MockServiceOldFeature());

            IMockInterface oldService = ServiceLocatorManager.Resolve <IMockInterface>();

            Assert.IsInstanceOf(typeof(MockServiceOldFeature), oldService);
        }
Exemple #12
0
        static MvcApplication()
        {
            // Register the IoC that you want Mvc Turbine to use!
            // Everything else is wired automatically

            // For now, let's use the Castle Windsor IoC since it will resolve the view engine's
            // default constructor
            ServiceLocatorManager.SetLocatorProvider(() => new WindsorServiceLocator());
        }
Exemple #13
0
        public void CreateNonMonoServiceDeleteItAndResolveIt()
        {
            Debug.logger.logEnabled = false;
            ServiceLocatorManager.Register <IMockInterface>(new MockServiceOldFeature());

            ServiceLocatorManager.Reset();

            IMockInterface service = ServiceLocatorManager.Resolve <IMockInterface>();

            Assert.IsNull(service);
        }
 /// <summary>
 /// Resolves singly registered services that support arbitrary object creation.
 /// </summary>
 /// <param name="serviceType">The type of the requested service or object.</param>
 /// <returns>
 /// The requested service or object.
 /// </returns>
 public object GetService(Type serviceType)
 {
     if (!ServiceLocatorManager.HasIgnoreServiceLocator(serviceType))
     {
         if (!serviceType.IsInterface && !serviceType.IsAbstract)
         {
             return(ServiceLocator.Resolve(serviceType));
         }
     }
     return(null);
 }
 /// <summary>
 /// Releases the specified controller.
 /// </summary>
 /// <param name="controller">The controller to release.</param>
 public override void ReleaseController(IController controller)
 {
     if (!ServiceLocatorManager.HasIgnoreServiceLocator(controller))
     {
         var disposable = (controller as IDisposable);
         if (disposable != null)
         {
             disposable.Dispose();
         }
         ServiceLocator.Release(controller);
     }
     base.ReleaseController(controller);
 }
Exemple #16
0
        public void CreateMonoServiceResetItAndResolveIt()
        {
            Debug.unityLogger.logEnabled = false;

            serviceLocatorManager.Register <IMockInterface>(ServiceLocatorManager.AsMono <MonoMockServiceFeature>());

            serviceLocatorManager.Reset();

            IMockInterface service = serviceLocatorManager.Resolve <IMockInterface>();
            var            obj     = Object.FindObjectOfType <MonoMockServiceFeature>();

            Assert.IsNull(obj);
        }
Exemple #17
0
        /// <summary>
        /// Binds the model by using the specified controller context and binding context.
        /// </summary>
        /// <param name="controllerContext">The context within which the controller operates. The context information includes the controller, HTTP content, request context, and route data.</param>
        /// <param name="bindingContext">The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.</param>
        /// <returns>
        /// The bound object.
        /// </returns>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="bindingContext "/>parameter is null.</exception>
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var controllerType = controllerContext.Controller.GetType();
            IEnumerable <IInjectableModelBinder> modelBinders;

            if (!ServiceLocatorManager.HasIgnoreServiceLocator(controllerType) && (modelBinders = GetModelBinders()) != null)
            {
                foreach (var modelBinder in modelBinders.Where(x => x.InjectForModelType(bindingContext.ModelType)))
                {
                    return(modelBinder.BindModel(controllerContext, bindingContext));
                }
            }
            return(base.BindModel(controllerContext, bindingContext));
        }
 /// <summary>
 /// Retrieves the controller instance for the specified request context and controller type.
 /// </summary>
 /// <param name="requestContext">The context of the HTTP request, which includes the HTTP context and route data.</param>
 /// <param name="controllerType">The type of the controller.</param>
 /// <returns>
 /// The controller instance.
 /// </returns>
 /// <exception cref="T:System.Web.HttpException">
 ///   <paramref name="controllerType"/> is null.</exception>
 ///
 /// <exception cref="T:System.ArgumentException">
 ///   <paramref name="controllerType"/> cannot be assigned.</exception>
 ///
 /// <exception cref="T:System.InvalidOperationException">An instance of <paramref name="controllerType"/> cannot be created.</exception>
 protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
 {
     // skips and calls to base if controllerType = null, throw standard MVC exception
     if (!ServiceLocatorManager.HasIgnoreServiceLocator(controllerType))
     {
         var controller             = ServiceLocator.Resolve <IController>(controllerType);
         var controllerAsController = (controller as Controller);
         if (controllerAsController != null)
         {
             controllerAsController.ActionInvoker = GetActionInvoker();
         }
         return(controller);
     }
     return(base.GetControllerInstance(requestContext, controllerType));
 }
        static void Main(string[] args)
        {
            ServiceLocatorManager.SetProvider(() => new UnityServiceLocator());
            ServiceBusManager.SetProvider(() => new RhinoServiceBusAbstractor())
            .AddMessageHandler(null)
            .AddMessageHandler(null);


            var serviceBus = ServiceBusManager.Current;

            serviceBus.Send <Message>(x =>
            {
                x.Name = "George";
            });
        }
 static Bootstrap()
 {
     ServiceLogManager.SetProvider(() => new Log4NetServiceLog("Dagent"));
     ServiceLocatorManager.SetProvider(() => new UnityServiceLocator()) // new MicroServiceLocator())
     .Register(r =>
     {
         ConfigurationManagerEx.GetSection <HostingSection>("hosting").Configure(r);
         var appSection = ConfigurationManagerEx.GetSection <AppSection>("appSection").Configure(r);
         if (appSection.Log4Net)
         {
             XmlConfigurator.Configure();
         }
         HostingEnvironment.Initialize();
     });
     var o = ServiceLocatorManager.Current;
 }
Exemple #21
0
        public IEnumerator CreateMonoServiceResetItAndResolveIt()
        {
            Debug.logger.logEnabled = false;

            ServiceLocatorManager.Register <IMockInterface>(ServiceLocatorManager.AsMono <MonoMockServiceFeature>());

            ServiceLocatorManager.Reset();

            IMockInterface service = ServiceLocatorManager.Resolve <IMockInterface>();

            Assert.IsNull(service);
            yield return(new WaitForEndOfFrame());

            var obj = Object.FindObjectOfType <MonoMockServiceFeature>();

            Assert.IsNull(obj);
        }
Exemple #22
0
            void ISetupDescriptor.RegisterWithServiceLocator(Lazy <TIService> service, Lazy <IServiceLocator> locator, string name)
            {
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (locator == null)
                {
                    throw new ArgumentNullException("locator", "Unable to locate ServiceLocator, please ensure this is defined first.");
                }
                var serviceRegistrar = _registration.DefaultServiceRegistrar;

                if (serviceRegistrar == null)
                {
                    throw new NullReferenceException("registration.ServiceLocatorRegistrar");
                }
                if (!locator.IsValueCreated)
                {
                    // question: should this use RegisterWithServiceLocator below?
                    var descriptor = ServiceLocatorManager.GetSetupDescriptor(locator);
                    if (descriptor == null)
                    {
                        throw new NullReferenceException();
                    }
                    descriptor.Do(l => serviceRegistrar(service.Value, l, name));
                }
                else
                {
                    var descriptor = GetSetupDescriptorProtected(service, null);
                    if (descriptor == null)
                    {
                        throw new NullReferenceException();
                    }
                    descriptor.Do(s => serviceRegistrar(s, locator.Value, name));
                }
            }
Exemple #23
0
 static MvcApplication()
 {
     ServiceLocatorManager.SetLocatorProvider(() => new WindsorServiceLocator());
 }
Exemple #24
0
 //NOTE: You want to hit this piece of code only once.
 static DefaultMvcApplication()
 {
     //TODO: Specify your own service locator here.
     ServiceLocatorManager.SetLocatorProvider(() => new WindsorServiceLocator());
 }
 /// <summary>
 /// Performs any startup processing.
 /// </summary>
 public override void Startup()
 {
     ServiceLocatorManager.SetLocatorProvider(() => new TurbineServiceLocatorAbstractor());
     base.Startup();
 }
 static SpringServiceLocator()
 {
     ServiceLocatorManager.EnsureRegistration();
 }
Exemple #27
0
 /// <summary>
 /// Static constructor.
 /// </summary>
 static OkonauApplication()
 {
     // Specify the Windsor IoC to use with the application.
     ServiceLocatorManager.SetLocatorProvider(() => new WindsorServiceLocator());
 }
 public MvcApplication()
 {
     ServiceLocatorManager.SetLocatorProvider(() => new UnityServiceLocator());
     this.AuthenticateRequest += new EventHandler(Application_AuthenticateRequest);
 }
Exemple #29
0
        public void Null_Provider_Throws_InvalidOperation_Exception()
        {
            ServiceLocatorManager.SetLocatorProvider(null);

            var locator = ServiceLocatorManager.Current;
        }
Exemple #30
0
        //NOTE: You want to hit this piece of code only once.
        static DefaultMvcApplication()
        {
            var container = CreateContainer();

            ServiceLocatorManager.SetLocatorProvider(() => new WindsorServiceLocator(container));
        }