Ejemplo n.º 1
2
        private static void ConfigureContainer()
        {
            Container = new Container();

            // Basic test first
            Container.Register<IClient, TestClient>();

            // Singletons can be set up using Reuse - demo this by getting an instance, updating value, then resolving a new instance
            Container.Register<ISingletonClient, SingletonClient>(Reuse.Singleton);

            // Registering with a primitive type to be passed to constructor
            Container.Register<IServiceWithParameter, ServiceWithParameter>(Made.Of(() => new ServiceWithParameter(Arg.Index<string>(0)), requestIgnored => "this is the parameter"));

            // Then registering a complex object instance to be used
            Container.Register<TestObject>();
            var testObj = new TestObject
            {
                ObjectName = "Ian",
                ObjectType = "Person"
            };
            // Register the instance above (into the container) - giving it an Id ("serviceKey") = "obj1"
            Container.RegisterInstance<TestObject>(testObj, serviceKey: "obj1");
            // Register ServiceWithTypeParameter - saying "When you make me a ServiceWithTypeParameter; and a contructor needs a TestObject - use the one with Id "obj1"
            Container.Register<IServiceWithTypeParameter, ServiceWithTypeParameter>(made: Parameters.Of.Type<TestObject>(serviceKey: "obj1"));

            // And finally multiple implementations
            // Registering multiple interface implementations using an enum key
            Container.Register<IMultipleImplementations, MultipleImplementationOne>(serviceKey: InterfaceKey.FirstKey);
            Container.Register<IMultipleImplementations, MultipleImplementationTwo>(serviceKey: InterfaceKey.SecondKey);
        }
Ejemplo n.º 2
0
 public ServiceWithTypeParameter(TestObject param)
 {
     _paramObject = param;
 }
Ejemplo n.º 3
0
 public ServiceWithTypeParameter(TestObject param)
 {
     _paramObject = param;
 }