Exemple #1
0
        public static void Register(IRegistrator r)
        {
            // r.Register<IExportedService, ExportedService>();

            // Optionally using the MEF Exported services
            r.RegisterExports(typeof(ExportedService));
        }
Exemple #2
0
        // If you need the whole container then change parameter type from IRegistrator to IContainer
        public CompositionRoot(IRegistrator r)
        {
            r.Register <IHotelServices, HotelServices>(Reuse.Singleton);
            r.Register <IDataServices, DataServices>(Reuse.Transient);
            // r.Register<IScopedService, ScopedService>(Reuse.InCurrentScope);

            var assemblies = new[] { typeof(DataServices).GetAssembly() };

            r.RegisterExports(assemblies);
        }
Exemple #3
0
        // If you need the whole container then change parameter type from IRegistrator to IContainer
        public CompositionRoot(IRegistrator r)
        {
            r.Register <ISingletonService, SingletonService>(Reuse.Singleton);
            r.Register <ITransientService, TransientService>(Reuse.Transient);
            r.Register <IScopedService, ScopedService>(Reuse.InCurrentScope);

            // optional: MEF based auto-wiring
            var assemblies = new[] { typeof(ExportedService).GetAssembly() };

            r.RegisterExports(assemblies);
        }
Exemple #4
0
 /// <summary>First scans (<see cref="Scan"/>) provided assemblies to find types annotated with
 /// <see cref="ExportAttribute"/>, or <see cref="ExportManyAttribute"/>.
 /// Then registers found types into registrator/container.</summary>
 /// <param name="registrator">Container to register into</param>
 /// <param name="assemblies">Provides assemblies to scan for exported implementation types.</param>
 /// <remarks>In case of <see cref="ReflectionTypeLoadException"/> try get type with <see cref="ReflectionTools.GetLoadedTypes"/>.</remarks>
 public static void RegisterExports(this IRegistrator registrator, IEnumerable <Assembly> assemblies)
 {
     registrator.RegisterExports(Scan(assemblies));
 }
Exemple #5
0
 /// <summary>Registers implementation type(s) with provided registrator/container. Expects that
 /// implementation type are annotated with <see cref="ExportAttribute"/>, or <see cref="ExportManyAttribute"/>.</summary>
 /// <param name="registrator">Container to register types into.</param>
 /// <param name="types">Implementation types to register.</param>
 public static void RegisterExports(this IRegistrator registrator, params Type[] types)
 {
     registrator.RegisterExports((IEnumerable <Type>)types);
 }
Exemple #6
0
 /// <summary>Registers implementation type(s) with provided registrator/container. Expects that
 /// implementation type are annotated with <see cref="ExportAttribute"/>, or <see cref="ExportManyAttribute"/>.</summary>
 /// <param name="registrator">Container to register types into.</param>
 /// <param name="types">Provides types to peek exported implementation types from.</param>
 public static void RegisterExports(this IRegistrator registrator, IEnumerable <Type> types)
 {
     registrator.RegisterExports(types.ThrowIfNull().Select(GetRegistrationInfoOrDefault).Where(regInfo => regInfo != null));
 }