NuGet packages Ikc5.Prism.Settings

In this post I would like to announce three NuGet packages under the common title Ikc5.Prism.Settings: Ikc5.Prism.Settings.Library, Ikc5.Prism.Settings.Module and Ikc5.Prism.Settings.Application. These packages allow manipulate user settings in Prism applications and serialize/deserialize them in xml files. All package contains the same library and last two packages add models, view models and views to the project.

The packages are open-source project, full code is accessible on GitHub NuGet repository. Repository contains nuspec files and file trees for Ikc5.Prism.Settings.Application and Ikc5.Prism.Settings.Module packages. Symbol’s packages was pushed to SymbolSource.org. Example of the using this package is considered in the post Examples of using Ikc5.Prism.Settings.

The package Ikc5.Prism.Settings.Library is intended to be used in shared or common libraries. Developer could extend classes from the package, but the most useful could be classes derived from BaseXmlUserSettingsProvider. The library version 1.0.0.0 contains only two providers that serialize settings in xml files and saves it either in IsolatedStorage or in Settings folder (this name can be overridden) in application’s folder.

The second package Ikc5.Prism.Settings.Module is intended to be used in WPF Prism module. It adds files for the implementation user settings in MVVM approach and provides Readme.txt.

---------------------------------------------------
------------ Ikc5.Prism.Settings.Module -----------
---------------------------------------------------

This package is intended to be used in WPF Prism module.
It requires the following changes in $ProjectName$Module.cs:

public class $ProjectName$Module : IModule
{
	private readonly IRegionManager _regionManager;

	private readonly IUnityContainer _container;

	public $ProjectName$Module(IRegionManager regionManager, IUnityContainer container)
	{
		_regionManager = regionManager;
		_container = container;
		ConfigureContainer();
	}

	private void ConfigureContainer()
	{
		_container.RegisterType<ISettings, Settings>(new ContainerControlledLifetimeManager());
	}

	public void Initialize()
	{
		_regionManager.RegisterViewWithRegion($"{GetType().Name}{RegionNames.ModuleSettingsRegion}", typeof(SettingsView));
	}
}

In addition, the following files are added to the project:

+Model
	- ISettings.cs
		// empty interface for application-specific
		// settings
	- Settings.cs
		// empty class bases on library's classes, could
		// contains properties in the form:
		//private object _example;
		// /// <summary>
		// /// Example.
		// /// </summary>
		//[DefaultValue("Value")]
		//public object Example
		//{
		//	get { return _example; }
		//	set { SetProperty(ref _example, value); }
		//}
+ViewModels
	- DesignSettingsViewModel.cs
		// class for view model that is used in SettingView at design time.
		// could contins auto-properties with default implementation.
	- ISettingsViewModel.cs
		// interface is ready for use, as contains the same properties as ISettings
	- SettingsViewModel.cs
		// class bases on library's classes, could contains properties in the form:
		//private object _example;
		// /// <summary>
		// /// Example.
		// /// </summary>
		//public object Example
		//{
		//	get { return _example; }
		//	set { SetProperty(ref _example, value); }
		//}
+Views
	- SettingsView.xaml
		// usercontrol that should provide some GUI elements for settings
	- SettingsView.xaml.cs
		// default implementation, is ready for use

The third package Ikc5.Prism.Settings.Application is intended to be used in WPF Prism application. It adds files for the implementation user settings in MVVM model and provides Readme.txt. In addition to files from Ikc5.Prism.Settings.Module, it contains SettingsWindow.xaml that provides window for user settings from all loaded modules.

---------------------------------------------------
--------- Ikc5.Prism.Settings.Application ---------
---------------------------------------------------

This package is intended to be used in WPF Prism application.
It requires the following changes in Bootstrapper.cs:

Method ConfigureContainer():

	Container
		.RegisterType<IUserSettingsService, UserSettingsService>(new ContainerControlledLifetimeManager())
		.RegisterType<ILiteObjectService, LiteObjectService>(new ContainerControlledLifetimeManager())
		.RegisterType<ISettings, Settings>(new ContainerControlledLifetimeManager());

	Container.RegisterType(
		typeof(IUserSettingsProvider<>),
		typeof(LocalXmlUserSettingsProvider<>),
		new ContainerControlledLifetimeManager());

Method InitializeShell():

	// add some views to region adapter
	var regionManager = Container.Resolve<IRegionManager>();
	regionManager.RegisterViewWithRegion(RegionNames.AppSettingsRegion, typeof(SettingsView));

In addition, the following files are added to the project:

+Model
	- ISettings.cs
		// empty interface for application-specific
		// settings
	- Settings.cs
		// empty class bases on library's classes, could
		// contains properties in the form:
		//private object _example;
		// /// <summary>
		// /// Example.
		// /// </summary>
		//[DefaultValue("Value")]
		//public object Example
		//{
		//	get { return _example; }
		//	set { SetProperty(ref _example, value); }
		//}
+ViewModels
	- DesignSettingsViewModel.cs
		// class for view model that is used in SettingView at design time.
		// could contins auto-properties with default implementation.
	- ISettingsViewModel.cs
		// interface is ready for use, as contains the same properties as ISettings
	- SettingsViewModel.cs
		// class bases on library's classes, could contains properties in the form:
		//private object _example;
		// /// <summary>
		// /// Example.
		// /// </summary>
		//public object Example
		//{
		//	get { return _example; }
		//	set { SetProperty(ref _example, value); }
		//}
+Views
	- SettingsView.xaml
		// usercontrol that should provide some GUI elements for settings
	- SettingsView.xaml.cs
		// default implementation, is ready for use
	- SettingsWindow.xaml
		// window that shows settings views from application and all modules,
		// is ready for use
	- SettingsWindow.xaml.cs
		// implementation that allows serialize settings, is ready for use

One of the packages was created with nuspec file from Visual Studio project. Another two packages was created from file trees, and let me note some issues that I faced up:

  • lib folder should include subfolders for all addressed framework versions. In my case, there is was only one subfolder net451, as application was not tested for earlier versions;
  • if it is planned that package contains symbols, corresponding .pdb files should be included for each .dll;
  • source files are taken either from content folder, or via description in section of nuspec file; and section has precedence over content folder;
  • readme.txt is detected automatically and is shown to user after installing package.

Command that composes package from file tree is the following

nuget pack $PackageName$.nuspec -symbols -Verbosity detailed -OutputDirectory ..\Publish

and pushes it to both storages

cd $SolutionDir$\Publish
nuget $PackageName$.$Version$.nupkg API-key -Source https://www.nuget.org/api/v2/package

1. All used IP-addresses, names of servers, workstations, domains, are fictional and are used exclusively as a demonstration only.
2. Information is provided «AS IS».

3 thoughts on “NuGet packages Ikc5.Prism.Settings

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s