Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
multitons via lazy factory methods
  • Loading branch information
saadshams committed Dec 25, 2020
1 parent 555b7d0 commit e58a0b7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 14 deletions.
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
*.swp
*.*~
project.lock.json
.DS_Store
*.pyc
nupkg/

# Visual Studio Code
.vscode

# Rider
.idea

# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates

# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
[Oo]ut/
msbuild.log
msbuild.err
msbuild.wrn

# Visual Studio 2015
.vs/
4 changes: 2 additions & 2 deletions PureMVC/Core/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class Controller: IController
public Controller(string key)
{
multitonKey = key;
InstanceMap.TryAdd(multitonKey, new Lazy<IController>(this));
InstanceMap.TryAdd(multitonKey, new Lazy<IController>(() => this));
commandMap = new ConcurrentDictionary<string, Func<ICommand>>();
InitializeController();
}
Expand Down Expand Up @@ -97,7 +97,7 @@ protected virtual void InitializeController()
/// <returns>the Multiton instance of <c>Controller</c></returns>
public static IController GetInstance(string key, Func<string, IController> factory)
{
return InstanceMap.GetOrAdd(key, new Lazy<IController>(factory(key))).Value;
return InstanceMap.GetOrAdd(key, new Lazy<IController>(() => factory(key))).Value;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions PureMVC/Core/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Model: IModel
public Model(string key)
{
multitonKey = key;
InstanceMap.TryAdd(key, new Lazy<IModel>(this));
InstanceMap.TryAdd(key, new Lazy<IModel>(() => this));
proxyMap = new ConcurrentDictionary<string, IProxy>();
InitializeModel();
}
Expand Down Expand Up @@ -75,7 +75,7 @@ protected virtual void InitializeModel()
/// <returns>the instance for this Multiton key </returns>
public static IModel GetInstance(string key, Func<string, IModel> factory)
{
return InstanceMap.GetOrAdd(key, new Lazy<IModel>(factory(key))).Value;
return InstanceMap.GetOrAdd(key, new Lazy<IModel>(() => factory(key))).Value;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions PureMVC/Core/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class View: IView
public View(string key)
{
multitonKey = key;
InstanceMap.TryAdd(key, new Lazy<IView>(this));
InstanceMap.TryAdd(key, new Lazy<IView>(() => this));
mediatorMap = new ConcurrentDictionary<string, IMediator>();
observerMap = new ConcurrentDictionary<string, IList<IObserver>>();
InitializeView();
Expand Down Expand Up @@ -76,7 +76,7 @@ protected virtual void InitializeView()
/// <returns>the instance for this Multiton key </returns>
public static IView GetInstance(string key, Func<string, IView> factory)
{
return InstanceMap.GetOrAdd(key, new Lazy<IView>(factory(key))).Value;
return InstanceMap.GetOrAdd(key, new Lazy<IView>(() => factory(key))).Value;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions PureMVC/Patterns/Facade/Facade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class Facade: IFacade
public Facade(string key)
{
InitializeNotifier(key);
InstanceMap.TryAdd(key, new Lazy<IFacade>(this));
InstanceMap.TryAdd(key, new Lazy<IFacade>(() => this));
InitializeFacade();
}

Expand Down Expand Up @@ -66,7 +66,7 @@ protected virtual void InitializeFacade()
/// <returns>the Multiton instance of the Facade</returns>
public static IFacade GetInstance(string key, Func<string, IFacade> factory)
{
return InstanceMap.GetOrAdd(key, new Lazy<IFacade>(factory(key))).Value;
return InstanceMap.GetOrAdd(key, new Lazy<IFacade>(() => factory(key))).Value;
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions PureMVC/PureMVC.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<PackageId>PureMVC.Multicore</PackageId>
<Version>2.1.0</Version>
<Version>2.2.0</Version>
<Description>PureMVC is a lightweight framework for creating applications based upon the classic Model-View-Controller design meta-pattern.</Description>
<Copyright>Copyright © 2017 Saad Shams, Futurescale, Inc.</Copyright>
<license>Creative Commons Attribution 3.0</license>
Expand All @@ -15,8 +15,8 @@
<Authors>Saad Shams</Authors>
<Company>Futurescale, Inc.</Company>
<PackageTags>PureMVC Multicore MVC</PackageTags>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
<FileVersion>2.1.0.0</FileVersion>
<AssemblyVersion>2.2.0.0</AssemblyVersion>
<FileVersion>2.2.0.0</FileVersion>
<NeutralLanguage>en-US</NeutralLanguage>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions PureMVCTests/PureMVCTests.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0"/>
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0"/>
<PackageReference Include="MSTest.TestFramework" Version="1.4.0"/>
<PackageReference Include="coverlet.collector" Version="1.0.1"/>
Expand Down

0 comments on commit e58a0b7

Please sign in to comment.