Beispiel #1
0
        public string DoSomething()
        {
            //if i don't have the stored item, go get it from the class I don't have the source
            if (string.IsNullOrEmpty(_whatIdid))
            {
                _whatIdid = _nonCachedFoo.DoSomething();
            }

            return(_whatIdid);
        }
Beispiel #2
0
        // LoadFrom() goes through Fusion and can be redirected to another assembly at a different path
        // but with that same identity if one is already loaded in the LoadFrom context.
        // More details: http://stackoverflow.com/questions/1477843/difference-between-loadfile-and-loadfrom-with-net-assemblies
        public Result LoadFrom(string fileName, Input data)
        {
            var assembly = Assembly.LoadFrom(fileName);
            var type     = assembly.GetTypes();

            // TODO: Find first type that has DoSomething attribute and implements IDoSomething.
            // TODO: Create an instance of this type.

            IDoSomething doSomethingService = null; // TODO Save instance to variable.

            return(doSomethingService.DoSomething(data));
        }
Beispiel #3
0
        // More details: http://stackoverflow.com/questions/1477843/difference-between-loadfile-and-loadfrom-with-net-assemblies
        public Result LoadFrom(string fileName, Input data)
        {
            var assembly = Assembly.LoadFrom(fileName);
            var types    = assembly.GetTypes();

            Type type = types.FirstOrDefault(t => t.GetCustomAttribute <DoSomethingAttribute>() != null && !typeof(IDoSomething).IsAssignableFrom(t));
            // TODO: Find first type that has DoSomething attribute and implements IDoSomething.
            // TODO: Create an instance of this type.

            IDoSomething doSomethingService = null; // TODO Save instance to variable.


            return(doSomethingService.DoSomething(data));
        }
Beispiel #4
0
        // More details: http://stackoverflow.com/questions/1477843/difference-between-loadfile-and-loadfrom-with-net-assemblies
        public Result LoadFrom(string fileName, Input data)
        {
            var assembly = Assembly.LoadFrom(fileName);
            var types    = assembly.GetTypes();

            // TODO: Find first type that has DoSomething attribute and implements IDoSomething.
            var typeIDoSmth = types.Where(t => t.GetInterface("IDoSomething") != null && Attribute.IsDefined(t, typeof(DoSomethingAttribute))).FirstOrDefault();
            // TODO: Create an instance of this type.
            var instance = Activator.CreateInstance(typeIDoSmth);

            IDoSomething doSomethingService = instance as IDoSomething; // TODO Save instance to variable.

            return(doSomethingService.DoSomething(data));
        }
        // Before making this call make sure that MyInterface assembly is signed with mykey.snk file. See Signing tab in MyInterface project properties editor.
        // Usage:
        // result = loader.Load("MyLibrary, Version=1.2.3.4, Culture=neutral, PublicKeyToken=f46a87b3d9a80705", input)
        public Result Load(string assemblyString, Input data)
        {
            // LoadFile() doesn't bind through Fusion at all - the loader just goes ahead and loads exactly what the caller requested.
            // It doesn't use either the Load or the LoadFrom context.
            // LoadFile() has a catch. Since it doesn't use a binding context, its dependencies aren't automatically found in its directory.

            var assembly = Assembly.Load(assemblyString);
            var types    = assembly.GetTypes();

            // TODO: Find first type that has DoSomething attribute and implements IDoSomething.
            // TODO: Create an instance of this type.

            IDoSomething doSomethingService = null; // TODO Save instance to variable.

            return(doSomethingService.DoSomething(data));
        }
Beispiel #6
0
        // Before making this call make sure that MyInterface assembly is signed with mykey.snk file. See Signing tab in MyInterface project properties editor.
        // Usage:
        // result = loader.Load("MyLibrary, Version=1.2.3.4, Culture=neutral, PublicKeyToken=f46a87b3d9a80705", input)
        public Result Load(string assemblyString, Input data)
        {
            // LoadFile() doesn't bind through Fusion at all - the loader just goes ahead and loads exactly what the caller requested.
            // It doesn't use either the Load or the LoadFrom context.
            // LoadFile() has a catch. Since it doesn't use a binding context, its dependencies aren't automatically found in its directory.

            var assembly = Assembly.Load(assemblyString);
            var types    = assembly.GetTypes();

            // TODO: Find first type that has DoSomething attribute and implements IDoSomething.
            var typeIDoSmth = types.Where(t => t.GetInterface("IDoSomething") != null && Attribute.IsDefined(t, typeof(DoSomethingAttribute))).FirstOrDefault();
            // TODO: Create an instance of this type.
            var instance = Activator.CreateInstance(typeIDoSmth);

            IDoSomething doSomethingService = instance as IDoSomething; // TODO Save instance to variable.

            return(doSomethingService.DoSomething(data));
        }
        // Before making this call make sure that MyInterface assembly is signed with mykey.snk file. See Signing tab in MyInterface project properties editor.
        // Usage:
        // result = loader.Load("MyLibrary, Version=1.2.3.4, Culture=neutral, PublicKeyToken=f46a87b3d9a80705", input)
        public Result Load(string assemblyString, Input data)
        {
            // LoadFile() doesn't bind through Fusion at all - the loader just goes ahead and loads exactly what the caller requested.
            // It doesn't use either the Load or the LoadFrom context.
            // LoadFile() has a catch. Since it doesn't use a binding context, its dependencies aren't automatically found in its directory.

            var assembly = Assembly.Load(assemblyString);
            var types    = assembly.GetTypes(); //AnotherService and MyService

            // TODO: Find first type that has DoSomething attribute and implements IDoSomething.
            // TODO: Create an instance of this type.
            Type type = types.First(x =>
                                    x.GetCustomAttributes(typeof(DoSomethingAttribute)) != null && x.GetInterface("IDoSomething") != null);

            var instanceType = Activator.CreateInstance(type);

            IDoSomething doSomethingService = null; // TODO Save instance to variable.

            doSomethingService = (IDoSomething)instanceType;
            return(doSomethingService.DoSomething(data));
        }
Beispiel #8
0
        private static void Method1(Input input)
        {
            var appDomainSetup = new AppDomainSetup
            {
                ApplicationBase = AppDomain.CurrentDomain.BaseDirectory,
                PrivateBinPath  = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MyDomain")
            };

            // TODO Create a new domain with name MyDomain and appDomainSetup.
            AppDomain domain = null;

            // TODO Subscribe to the event that will be raised when assembly is loaded.
            {
                // TODO Set a full name of an assembly that is loaded.
                string assemblyFullName = string.Empty;
                Console.WriteLine("Assembly {0} is loaded.", assemblyFullName);
            };

            // TODO Create a new instance of DomainAssemblyLoader in MyDomain and unwrap it by using CreateInstanceAndUnwrap method and specifying class name.
            DomainAssemblyLoader loader = null; // domain.MethodName(Assembly.GetExecutingAssembly().FullName, typeof(ClassName).FullName);

            try
            {
                var assemblyString = "MyLibrary, Version=1.2.3.4, Culture=neutral, PublicKeyToken=f46a87b3d9a80705";

                // NOTE You will get an exception about serialization issues. Try to fix that using SerializableAttribute or MarshalByRefObject.
                IDoSomething doSomething = loader.Load <IDoSomething>(assemblyString);
                var          result      = doSomething.DoSomething(input);

                // TODO Put a breakpoint here and take a look at doSomething and result variables in the run time.

                Console.WriteLine("Method1: {0}", result.Value);
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: {0}", e.Message);
            }

            // TODO: Unload app. domain.
        }
Beispiel #9
0
        // Before making this call make sure that MyInterface assembly is signed with mykey.snk file. See Signing tab in MyInterface project properties editor.
        // Usage:
        // result = loader.Load("MyLibrary, Version=1.2.3.4, Culture=neutral, PublicKeyToken=f46a87b3d9a80705", input)
        public Result Load(string assemblyString, Input data)
        {
            // LoadFile() doesn't bind through Fusion at all - the loader just goes ahead and loads exactly what the caller requested.
            // It doesn't use either the Load or the LoadFrom context.
            // LoadFile() has a catch. Since it doesn't use a binding context, its dependencies aren't automatically found in its directory.

            var assembly = Assembly.Load(assemblyString);
            var types    = assembly.GetTypes();

            // TODO: Find first type that has DoSomething attribute and implements IDoSomething.
            // TODO: Create an instance of this type.

            IDoSomething doSomethingService = null; // TODO Save instance to variable.

            Type type = types.FirstOrDefault(t => t.GetCustomAttribute <DoSomethingAttribute>() != null && typeof(IDoSomething).IsAssignableFrom(t));

            if (!ReferenceEquals(type, null))
            {
                doSomethingService = (IDoSomething)Activator.CreateInstance(type);
            }

            return(doSomethingService.DoSomething(data));
        }
Beispiel #10
0
        // More details: http://stackoverflow.com/questions/1477843/difference-between-loadfile-and-loadfrom-with-net-assemblies
        public Result LoadFrom(string fileName, Input data)
        {
            var assembly = Assembly.LoadFrom(fileName);
            var types    = assembly.GetTypes();

            // TODO: Find first type that has DoSomething attribute and implements IDoSomething.

            var  typesWithAttribute = types.Where(t => t.GetCustomAttributes(typeof(DoSomethingAttribute), true).Length > 0);
            var  typeInterface      = typeof(IDoSomething);
            Type type = typesWithAttribute.First(p => typeInterface.IsAssignableFrom(p));

            // TODO: Create an instance of this type.

            var instance = Activator.CreateInstance(type);

            IDoSomething doSomethingService = null;

            // TODO Save instance to variable.

            doSomethingService = instance as IDoSomething;

            return(doSomethingService?.DoSomething(data));
        }
Beispiel #11
0
        // Before making this call make sure that MyInterface assembly is signed with mykey.snk file. See Signing tab in MyInterface project properties editor.
        // Usage:
        // result = loader.Load("MyLibrary, Version=1.2.3.4, Culture=neutral, PublicKeyToken=f46a87b3d9a80705", input)
        public Result Load(string assemblyString, Input data)
        {
            // LoadFile() doesn't bind through Fusion at all - the loader just goes ahead and loads exactly what the caller requested.
            // It doesn't use either the Load or the LoadFrom context.
            // LoadFile() has a catch. Since it doesn't use a binding context, its dependencies aren't automatically found in its directory.

            Console.WriteLine("Start Load(string assemblyString, Input data).");

            var assembly = Assembly.Load(assemblyString);
            var types    = assembly.GetTypes();

            Console.WriteLine("All types which were loaded from assembly:");
            foreach (var t in types)
            {
                Console.WriteLine(t);
            }

            // TODO: Find first type that has DoSomething attribute and implements IDoSomething.
            // TODO: Create an instance of this type.

            var  typesWithAttribute = types.Where(t => t.GetCustomAttributes(typeof(DoSomethingAttribute), true).Length > 0);
            var  typeInterface      = typeof(IDoSomething);
            Type type = typesWithAttribute.First(p => typeInterface.IsAssignableFrom(p));

            Console.WriteLine("Seeking type: " + type + "\nGet type this object: " + type.Name);

            var instance = Activator.CreateInstance(type);

            IDoSomething doSomethingService = null;

            // TODO Save instance to variable.

            doSomethingService = instance as IDoSomething;

            return(doSomethingService.DoSomething(data));
        }
 public void DoLibraryStuff(IDoSomething iDoSomething)
 {
     iDoSomething.DoSomething("info"); ...
Beispiel #13
0
 public void DoLibraryStuff(IDoSomething iDoSomething, string extraParam)
 {
     iDoSomething.DoSomething("info"); ...
Beispiel #14
0
 public void PerformSomething()
 {
     _doSomething.DoSomething();
 }
 public string Run(Guid id)
 {
     return(_something.DoSomething(id));
 }
 public static void DoThis(this IDoSomething x)
 {
     x.DoSomething(123);     //default value
 }
        public int DoSomething()
        {
            var doSomething = _someOtherComponent.DoSomething(42);

            return(42);
        }