142 lines
4.6 KiB
C#
142 lines
4.6 KiB
C#
|
|
using System;
|
|||
|
|
using System.ComponentModel.Composition;
|
|||
|
|
using System.Windows.Media.Imaging;
|
|||
|
|
using DTS.Common;
|
|||
|
|
using DTS.Common.Interface;
|
|||
|
|
using Prism.Modularity;
|
|||
|
|
using Unity;
|
|||
|
|
using HamburgerMenu;
|
|||
|
|
using DTS.Common.Interface.Menu.HamburgerMenu;
|
|||
|
|
using Prism.Ioc;
|
|||
|
|
using Unity.Lifetime;
|
|||
|
|
|
|||
|
|
// ReSharper disable CheckNamespace
|
|||
|
|
// ReSharper disable RedundantAttributeUsageProperty
|
|||
|
|
// ReSharper disable UnusedParameter.Local
|
|||
|
|
|
|||
|
|
[assembly: HamburgerMenuModuleName]
|
|||
|
|
[assembly: HamburgerMenuModuleImageAttribute]
|
|||
|
|
namespace HamburgerMenu
|
|||
|
|
{
|
|||
|
|
[Export(typeof(IModule))]
|
|||
|
|
[Module(ModuleName = "HamburgerMenuModule")]
|
|||
|
|
public class HamburgerMenuModule : IModule
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Injected unity container
|
|||
|
|
/// </summary>
|
|||
|
|
private readonly IUnityContainer _unityContainer;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Initializes a new instance of the <see cref="HamburgerMenuModule"/> class.
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="unityContainer">Obtained reference of the unity container by using dependency injection.</param>
|
|||
|
|
public HamburgerMenuModule(IUnityContainer unityContainer)
|
|||
|
|
{
|
|||
|
|
_unityContainer = unityContainer;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Initialize()
|
|||
|
|
{
|
|||
|
|
// Register View & View-Model with Unity dependency injection container as a singleton.
|
|||
|
|
//FB 39426 Added lifetime manager to make the instance singleton
|
|||
|
|
//https://www.tutorialsteacher.com/ioc/register-and-resolve-in-unity-container
|
|||
|
|
_unityContainer.RegisterType<IHamburgerMenuView, HamburgerMenuView>(new ContainerControlledLifetimeManager());
|
|||
|
|
_unityContainer.RegisterType<IHamburgerMenuViewModel, HamburgerMenuViewModel>(new ContainerControlledLifetimeManager());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void OnInitialized(IContainerProvider containerProvider)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void RegisterTypes(IContainerRegistry containerRegistry)
|
|||
|
|
{
|
|||
|
|
Initialize();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Attribute class contains assembly name
|
|||
|
|
/// </summary>
|
|||
|
|
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
|
|||
|
|
public class HamburgerMenuModuleNameAttribute : TextAttribute
|
|||
|
|
{
|
|||
|
|
public HamburgerMenuModuleNameAttribute() : this(null) { }
|
|||
|
|
|
|||
|
|
public HamburgerMenuModuleNameAttribute(string s)
|
|||
|
|
{
|
|||
|
|
AssemblyName = AssemblyNames.HamburgerMenu.ToString();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override string AssemblyName { get; }
|
|||
|
|
|
|||
|
|
public override Type GetAttributeType()
|
|||
|
|
{
|
|||
|
|
return typeof(TextAttribute);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override string GetAssemblyName()
|
|||
|
|
{
|
|||
|
|
return AssemblyName;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Attribute class contains assembly image and name - used on the Main screen to SummaryModule available components
|
|||
|
|
/// </summary>
|
|||
|
|
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
|
|||
|
|
public class HamburgerMenuModuleImageAttribute : ImageAttribute
|
|||
|
|
{
|
|||
|
|
private BitmapImage _img;
|
|||
|
|
|
|||
|
|
public HamburgerMenuModuleImageAttribute() : this(null) { }
|
|||
|
|
public override BitmapImage AssemblyImage
|
|||
|
|
{
|
|||
|
|
get { _img = AssemblyInfo.GetImage(AssemblyNames.HamburgerMenu.ToString()); return _img; }
|
|||
|
|
}
|
|||
|
|
public HamburgerMenuModuleImageAttribute(string s)
|
|||
|
|
{
|
|||
|
|
_img = AssemblyInfo.GetImage(AssemblyNames.HamburgerMenu.ToString());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override Type GetAttributeType()
|
|||
|
|
{
|
|||
|
|
return typeof(ImageAttribute);
|
|||
|
|
}
|
|||
|
|
public override BitmapImage GetAssemblyImage()
|
|||
|
|
{
|
|||
|
|
return AssemblyImage;
|
|||
|
|
}
|
|||
|
|
private string _name;
|
|||
|
|
public override string AssemblyName
|
|||
|
|
{
|
|||
|
|
get { _name = AssemblyNames.HamburgerMenu.ToString(); return _name; }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override string GetAssemblyName()
|
|||
|
|
{
|
|||
|
|
return AssemblyName;
|
|||
|
|
}
|
|||
|
|
private string _group;
|
|||
|
|
public override string AssemblyGroup
|
|||
|
|
{
|
|||
|
|
get { _group = eAssemblyGroups.Prepare.ToString(); return _group; }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override string GetAssemblyGroup()
|
|||
|
|
{
|
|||
|
|
return AssemblyGroup;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private eAssemblyRegion _region;
|
|||
|
|
public override eAssemblyRegion AssemblyRegion
|
|||
|
|
{
|
|||
|
|
get { _region = eAssemblyRegion.HamburgerMenuRegion; return _region; }
|
|||
|
|
}
|
|||
|
|
public override eAssemblyRegion GetAssemblyRegion()
|
|||
|
|
{
|
|||
|
|
return AssemblyRegion;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|