Do

Merge lp:~alexlauni/do/IStrictService into lp:do

Proposed by Alex Launi
Status: Merged
Merged at revision: not available
Proposed branch: lp:~alexlauni/do/IStrictService
Merge into: lp:do
Diff against target: None lines
To merge this branch: bzr merge lp:~alexlauni/do/IStrictService
Reviewer Review Type Date Requested Status
Jason Smith (community) Approve
Robert Dyer (community) Approve
Review via email: mp+7760@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alex Launi (alexlauni) wrote :

Adds a type of service called IStrictService that does not get lazy loaded, rather gets initialized when the service manager comes up. Most services can lazy load, but there are some cases (such as the PackageManager service that will be coming in a later merge) that cannot be lazy loaded and need to be created immediately.

Revision history for this message
Robert Dyer (psybers) wrote :

1. In the comment for 'InitializeIStrictServices' you mention looping to find IStatic (should be IStrictService?)

2. I don't like 'InitializeIStrictServices' as a method name. If you wind up deciding 'strict services' should be implemented via a different type hierarchy you will have to rename this method to mirror. I think 'InitializeStrictServices' is better (notice the lack of 'I', thus this method is not named after the type but rather after what it does).

review: Needs Fixing
lp:~alexlauni/do/IStrictService updated
1250. By Alex Launi

Fix a comment typo and make a method name cleaner as per PsyberS' review

Revision history for this message
Alex Launi (alexlauni) wrote :

Fixed

Revision history for this message
Robert Dyer (psybers) :
review: Approve
Revision history for this message
Jason Smith (jassmith) wrote :

Looks good buddy, the part you noted as looking silly does indeed look silly... I wonder why they did it that way, but it is noted so no big deal.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Do.Platform/Do.Platform.mdp'
2--- Do.Platform/Do.Platform.mdp 2009-06-10 05:30:30 +0000
3+++ Do.Platform/Do.Platform.mdp 2009-06-22 15:41:57 +0000
4@@ -79,6 +79,7 @@
5 <File name="src/Do.Platform/INetworkService.cs" subtype="Code" buildaction="Compile" />
6 <File name="src/Do.Platform/NetworkStateChangedEventArgs.cs" subtype="Code" buildaction="Compile" />
7 <File name="src/Do.Platform/Do.Platform.Default/NetworkService.cs" subtype="Code" buildaction="Compile" />
8+ <File name="src/Do.Platform/Do.Platform.ServiceStack/IStrictService.cs" subtype="Code" buildaction="Compile" />
9 </Contents>
10 <References>
11 <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
12
13=== modified file 'Do.Platform/Makefile.am'
14--- Do.Platform/Makefile.am 2009-06-10 05:30:30 +0000
15+++ Do.Platform/Makefile.am 2009-06-22 15:41:57 +0000
16@@ -30,6 +30,7 @@
17 src/Do.Platform/Do.Platform.Preferences/PreferencesImplementation.cs \
18 src/Do.Platform/Do.Platform.ServiceStack/IInitializedService.cs \
19 src/Do.Platform/Do.Platform.ServiceStack/IService.cs \
20+ src/Do.Platform/Do.Platform.ServiceStack/IStrictService.cs \
21 src/Do.Platform/ICoreService.cs \
22 src/Do.Platform/IEnvironmentService.cs \
23 src/Do.Platform/ILogService.cs \
24
25=== added file 'Do.Platform/src/Do.Platform/Do.Platform.ServiceStack/IStrictService.cs'
26--- Do.Platform/src/Do.Platform/Do.Platform.ServiceStack/IStrictService.cs 1970-01-01 00:00:00 +0000
27+++ Do.Platform/src/Do.Platform/Do.Platform.ServiceStack/IStrictService.cs 2009-06-22 15:41:57 +0000
28@@ -0,0 +1,31 @@
29+// %filename
30+//
31+// GNOME Do is the legal property of its developers. Please refer to the
32+// COPYRIGHT file distributed with this source distribution.
33+//
34+// This program is free software: you can redistribute it and/or modify
35+// it under the terms of the GNU General Public License as published by
36+// the Free Software Foundation, either version 3 of the License, or
37+// (at your option) any later version.
38+//
39+// This program is distributed in the hope that it will be useful,
40+// but WITHOUT ANY WARRANTY; without even the implied warranty of
41+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42+// GNU General Public License for more details.
43+//
44+// You should have received a copy of the GNU General Public License
45+// along with this program. If not, see <http://www.gnu.org/licenses/>.
46+
47+using System;
48+
49+namespace Do.Platform
50+{
51+
52+ /// <summary>
53+ /// If your service cannot be lazy loaded, and need initialization use this interface.
54+ /// This will cause your service to be initialized with the Service manager.
55+ /// </summary>
56+ public interface IStrictService
57+ {
58+ }
59+}
60
61=== modified file 'Do.Platform/src/Do.Platform/Services.cs'
62--- Do.Platform/src/Do.Platform/Services.cs 2009-06-10 05:30:30 +0000
63+++ Do.Platform/src/Do.Platform/Services.cs 2009-06-22 15:41:57 +0000
64@@ -19,6 +19,7 @@
65
66 using System;
67 using System.Linq;
68+using System.Reflection;
69 using System.Collections.Generic;
70
71 using Mono.Addins;
72@@ -60,6 +61,7 @@
73 throw new Exception ("AddinManager was initialized before Services.");
74 }
75 AddinManager.AddExtensionNodeHandler ("/Do/Service", OnServiceChanged);
76+ InitializeIStrictServices ();
77 }
78
79 /// <summary>
80@@ -229,5 +231,20 @@
81 return Enumerable.Empty<TService> ();
82 }
83 }
84+
85+ /// <summary>
86+ /// loops through the Property members of this class, and if it's an IStatic gets it's value.
87+ /// This will in turn cause a LocateService call, and the appropriate service will be loaded.
88+ /// </summary>
89+ static void InitializeIStrictServices ()
90+ {
91+ foreach (PropertyInfo property in typeof (Services).GetProperties ()) {
92+ Type returnType = property.PropertyType;
93+ if (returnType.GetInterface ("Do.Platform.IStrictService") != null) {
94+ // this looks stupid, but this is how you call the method on static classes.
95+ property.GetValue (null, null);
96+ }
97+ }
98+ }
99 }
100 }