Skip to content

Commit 70c9626

Browse files
authored
Remove IPublishedSnapshotAccessor from various code samples (#7100)
* Removed IPublishedSnapshotAccessor from V15 code samples * Removed IPublishedSnapshotAccessor from V16 code samples
1 parent 58a30bd commit 70c9626

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+688
-982
lines changed

15/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/checkbox-list.md

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ You can use dictionary items to translate the options in a Checkbox List propert
2626

2727
## MVC View Example
2828

29-
### Without Modelsbuilder
29+
### Without Models Builder
3030

3131
```csharp
3232
@{
@@ -42,7 +42,7 @@ You can use dictionary items to translate the options in a Checkbox List propert
4242
}
4343
```
4444

45-
### With Modelsbuilder
45+
### With Models Builder
4646

4747
```csharp
4848
@{
@@ -67,25 +67,22 @@ The example below demonstrates how to add values programmatically using a Razor
6767
{% endhint %}
6868

6969
```csharp
70-
@inject IContentService Services;
7170
@using Umbraco.Cms.Core.Serialization
72-
@using Umbraco.Cms.Core.Services;
73-
@inject IJsonSerializer Serializer;
71+
@using Umbraco.Cms.Core.Services
72+
@inject IContentService ContentService
73+
@inject IJsonSerializer Serializer
7474
@{
75-
// Get access to ContentService
76-
var contentService = Services;
77-
7875
// Create a variable for the GUID of the page you want to update
7976
var guid = Guid.Parse("32e60db4-1283-4caa-9645-f2153f9888ef");
8077

8178
// Get the page using the GUID you've defined
82-
var content = contentService.GetById(guid); // ID of your page
79+
var content = ContentService.GetById(guid); // ID of your page
8380
84-
// Set the value of the property with alias 'superHeros'.
85-
content.SetValue("superHeros", Serializer.Serialize(new[] { "Umbraco", "CodeGarden"}));
81+
// Set the value of the property with alias 'superHeroes'.
82+
content.SetValue("superHeroes", Serializer.Serialize(new[] { "Umbraco", "CodeGarden"}));
8683

8784
// Save the change
88-
contentService.Save(content);
85+
ContentService.Save(content);
8986
}
9087
```
9188

@@ -94,20 +91,17 @@ Although the use of a GUID is preferable, you can also use the numeric ID to get
9491
```csharp
9592
@{
9693
// Get the page using it's id
97-
var content = contentService.GetById(1234);
94+
var content = ContentService.GetById(1234);
9895
}
9996
```
10097

101-
If Modelsbuilder is enabled you can get the alias of the desired property without using a magic string:
102-
103-
{% include "../../../../.gitbook/includes/obsolete-warning-ipublishedsnapshotaccessor.md" %}
98+
If Models Builder is enabled you can get the alias of the desired property without using a magic string:
10499

105100
```csharp
106-
@inject IPublishedSnapshotAccessor _publishedSnapshotAccessor;
107-
@using Umbraco.Cms.Core.PublishedCache;
101+
@using Umbraco.Cms.Core.PublishedCache
102+
@inject IPublishedContentTypeCache PublishedContentTypeCache
108103
@{
109-
110-
// Set the value of the property with alias 'superHeros'
111-
content.SetValue(Home.GetModelPropertyType(_publishedSnapshotAccessor,x => x.SuperHeros).Alias, Serializer.Serialize(new[] { "Umbraco", "CodeGarden"}));
104+
// Set the value of the property with alias 'superHeroes'
105+
content.SetValue(Home.GetModelPropertyType(PublishedContentTypeCache, x => x.SuperHeroes).Alias, Serializer.Serialize(new[] { "Umbraco", "CodeGarden"}));
112106
}
113107
```

15/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/color-picker.md

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ It is possible to add a label to use with the color.
2020

2121
![Color Picker Content](../../../../../../10/umbraco-cms/fundamentals/backoffice/property-editors/built-in-property-editors/images/Color-Picker-Content-v8.png)
2222

23-
## Example with Modelsbuilder
23+
## Example with Models Builder
2424

2525
```csharp
2626
@{
@@ -36,7 +36,7 @@ It is possible to add a label to use with the color.
3636
}
3737
```
3838

39-
## Example without Modelsbuilder
39+
## Example without Models Builder
4040

4141
```csharp
4242
@using Umbraco.Cms.Core.PropertyEditors.ValueConverters
@@ -64,48 +64,42 @@ The example below demonstrates how to add values programmatically using a Razor
6464
### Without labels
6565

6666
```csharp
67-
@inject IContentService Services;
68-
@using Umbraco.Cms.Core.Services;
67+
@using Umbraco.Cms.Core.Services
68+
@inject IContentService ContentService
6969
@{
70-
// Get access to ContentService
71-
var contentService = Services;
72-
7370
// Create a variable for the GUID of the page you want to update
7471
var guid = Guid.Parse("32e60db4-1283-4caa-9645-f2153f9888ef");
7572

7673
// Get the page using the GUID you've defined
77-
var content = contentService.GetById(guid); // ID of your page
74+
var content = ContentService.GetById(guid); // ID of your page
7875
7976
// Set the value of the property with alias 'color'.
8077
// The value set here, needs to be one of the colors on the Color Picker
8178
content.SetValue("color", "38761d");
8279

8380
// Save the change
84-
contentService.Save(content);
81+
ContentService.Save(content);
8582
}
8683
```
8784

8885
### With labels
8986

9087
```csharp
91-
@inject IContentService Services;
92-
@using Umbraco.Cms.Core.Services;
88+
@using Umbraco.Cms.Core.Services
89+
@inject IContentService ContentService
9390
@{
94-
// Get access to ContentService
95-
var contentService = Services;
96-
9791
// Create a variable for the GUID of the page you want to update
9892
var guid = Guid.Parse("32e60db4-1283-4caa-9645-f2153f9888ef");
9993

10094
// Get the page using the GUID you've defined
101-
var content = contentService.GetById(guid); // ID of your page
95+
var content = ContentService.GetById(guid); // ID of your page
10296
10397
// Set the value of the property with alias 'color'.
10498
// The value set here, needs to be one of the colors on the Color Picker
10599
content.SetValue("color", "{'value':'000000', 'label':'Black', 'sortOrder':1, 'id':'1'}");
106100

107101
// Save the change
108-
contentService.Save(content);
102+
ContentService.Save(content);
109103
}
110104
```
111105

@@ -114,19 +108,17 @@ Although the use of a GUID is preferable, you can also use the numeric ID to get
114108
```csharp
115109
@{
116110
// Get the page using it's id
117-
var content = contentService.GetById(1234);
111+
var content = ContentService.GetById(1234);
118112
}
119113
```
120114

121-
If Modelsbuilder is enabled you can get the alias of the desired property without using a magic string:
122-
123-
{% include "../../../../.gitbook/includes/obsolete-warning-ipublishedsnapshotaccessor.md" %}
115+
If Models Builder is enabled you can get the alias of the desired property without using a magic string:
124116

125117
```csharp
126-
@inject IPublishedSnapshotAccessor _publishedSnapshotAccessor;
127-
@using Umbraco.Cms.Core.PublishedCache;
118+
@using Umbraco.Cms.Core.PublishedCache
119+
@inject IPublishedContentTypeCache PublishedContentTypeCache
128120
@{
129121
// Set the value of the property with alias 'color'
130-
content.SetValue(Home.GetModelPropertyType(_publishedSnapshotAccessor, x => x.Color).Alias, "38761d");
122+
content.SetValue(Home.GetModelPropertyType(PublishedContentTypeCache, x => x.Color).Alias, "38761d");
131123
}
132124
```

15/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/content-picker.md

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ When opening the picker on the `Umbraco anno MMXXIII` node, it will now show the
200200

201201
## MVC View Example
202202

203-
### Without Modelsbuilder
203+
### Without Models Builder
204204

205205
```csharp
206206
@{
@@ -213,7 +213,7 @@ When opening the picker on the `Umbraco anno MMXXIII` node, it will now show the
213213
}
214214
```
215215

216-
### With Modelsbuilder
216+
### With Models Builder
217217

218218
```csharp
219219
@{
@@ -234,19 +234,15 @@ The example below demonstrates how to add values programmatically using a Razor
234234
{% endhint %}
235235

236236
```csharp
237-
@inject IContentService Services;
238-
@using Umbraco.Cms.Core;
237+
@using Umbraco.Cms.Core
239238
@using Umbraco.Cms.Core.Services
240-
239+
@inject IContentService ContentService
241240
@{
242-
// Get access to ContentService
243-
var contentService = Services;
244-
245241
// Create a variable for the GUID of the page you want to update
246242
var guid = Guid.Parse("32e60db4-1283-4caa-9645-f2153f9888ef");
247243

248244
// Get the page using the GUID you've defined
249-
var content = contentService.GetById(guid); // ID of your page
245+
var content = ContentService.GetById(guid); // ID of your page
250246
251247
// Get the pages you want to assign to the Content Picker
252248
var page = Umbraco.Content("665d7368-e43e-4a83-b1d4-43853860dc45");
@@ -263,7 +259,7 @@ The example below demonstrates how to add values programmatically using a Razor
263259
content.SetValue("featuredArticles", string.Join(",", udis));
264260

265261
// Save the change
266-
contentService.Save(content);
262+
ContentService.Save(content);
267263
}
268264
```
269265

@@ -272,20 +268,17 @@ Although the use of a GUID is preferable, you can also use the numeric ID to get
272268
```csharp
273269
@{
274270
// Get the page using it's id
275-
var content = contentService.GetById(1234);
271+
var content = ContentService.GetById(1234);
276272
}
277273
```
278274

279-
If Modelsbuilder is enabled you can get the alias of the desired property without using a magic string:
280-
281-
{% include "../../../../.gitbook/includes/obsolete-warning-ipublishedsnapshotaccessor.md" %}
275+
If Models Builder is enabled you can get the alias of the desired property without using a magic string:
282276

283277
```csharp
284-
@inject IPublishedSnapshotAccessor _publishedSnapshotAccessor;
285-
@using Umbraco.Cms.Core.PublishedCache;
286-
278+
@using Umbraco.Cms.Core.PublishedCache
279+
@inject IPublishedContentTypeCache PublishedContentTypeCache
287280
@{
288281
// Set the value of the property with alias 'featuredArticles'
289-
content.SetValue(Home.GetModelPropertyType(_publishedSnapshotAccessor ,x => x.FeaturedArticles).Alias, string.Join(",", udis));
282+
content.SetValue(Home.GetModelPropertyType(PublishedContentTypeCache, x => x.FeaturedArticles).Alias, string.Join(",", udis));
290283
}
291284
```

15/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/date-time.md

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ The setting involves defining the format. The default date format in the Umbraco
2222

2323
## MVC View Example - displays a datetime
2424

25-
### With Modelsbuilder
25+
### With Models Builder
2626

2727
```csharp
2828
@Model.DatePicker
2929
```
3030

31-
### Without Modelsbuilder
31+
### Without Models Builder
3232

3333
```csharp
3434
@Model.Value("datePicker")
@@ -43,23 +43,20 @@ The example below demonstrates how to add values programmatically using a Razor
4343
{% endhint %}
4444

4545
```csharp
46-
@inject IContentService Services;
47-
@using Umbraco.Cms.Core.Services;
46+
@using Umbraco.Cms.Core.Services
47+
@inject IContentService ContentService
4848
@{
49-
// Get access to ContentService
50-
var contentService = Services;
51-
5249
// Create a variable for the GUID of the page you want to update
5350
var guid = new Guid("32e60db4-1283-4caa-9645-f2153f9888ef");
5451

5552
// Get the page using the GUID you've defined
56-
var content = contentService.GetById(guid); // ID of your page
53+
var content = ContentService.GetById(guid); // ID of your page
5754
5855
// Set the value of the property with alias 'datePicker'
5956
content.SetValue("datePicker", DateTime.Now);
6057

6158
// Save the change
62-
contentService.Save(content);
59+
ContentService.Save(content);
6360
}
6461
```
6562

@@ -68,20 +65,18 @@ Although the use of a GUID is preferable, you can also use the numeric ID to get
6865
```csharp
6966
@{
7067
// Get the page using it's id
71-
var content = contentService.GetById(1234);
68+
var content = ContentService.GetById(1234);
7269
}
7370
```
7471

75-
If Modelsbuilder is enabled you can get the alias of the desired property without using a magic string:
76-
77-
{% include "../../../../.gitbook/includes/obsolete-warning-ipublishedsnapshotaccessor.md" %}
72+
If Models Builder is enabled you can get the alias of the desired property without using a magic string:
7873

7974
```csharp
80-
@using Umbraco.Cms.Core.PublishedCache;
81-
@inject IPublishedSnapshotAccessor _publishedSnapshotAccessor;
75+
@using Umbraco.Cms.Core.PublishedCache
76+
@inject IPublishedContentTypeCache PublishedContentTypeCache
8277
@{
8378

8479
// Set the value of the property with alias 'datePicker'
85-
content.SetValue(Home.GetModelPropertyType(_publishedSnapshotAccessor, x => x.DatePicker).Alias, DateTime.Now);
80+
content.SetValue(Home.GetModelPropertyType(PublishedContentTypeCache, x => x.DatePicker).Alias, DateTime.Now);
8681
}
8782
```

15/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/decimal.md

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ If the value of **Step Size** is not set then all decimal values between 8 and 1
2222

2323
## MVC View Example
2424

25-
### With Modelsbuilder
25+
### With Models Builder
2626

2727
```csharp
2828
@Model.MyDecimal
2929
```
3030

31-
### Without Modelsbuilder
31+
### Without Models Builder
3232

3333
```csharp
3434
@Model.Value("MyDecimal")
@@ -43,23 +43,20 @@ The example below demonstrates how to add values programmatically using a Razor
4343
{% endhint %}
4444

4545
```csharp
46-
@inject IContentService Services;
47-
@using Umbraco.Cms.Core.Services;
46+
@using Umbraco.Cms.Core.Services
47+
@inject IContentService ContentService
4848
@{
49-
// Get access to ContentService
50-
var contentService = Services;
51-
5249
// Create a variable for the GUID of the page you want to update
5350
var guid = Guid.Parse("32e60db4-1283-4caa-9645-f2153f9888ef");
5451

5552
// Get the page using the GUID you've defined
56-
var content = contentService.GetById(guid); // ID of your page
53+
var content = ContentService.GetById(guid); // ID of your page
5754
5855
// Set the value of the property with alias 'myDecimal'.
5956
content.SetValue("myDecimal", 3);
6057

6158
// Save the change
62-
contentService.Save(content);
59+
ContentService.Save(content);
6360
}
6461
```
6562

@@ -68,19 +65,17 @@ Although the use of a GUID is preferable, you can also use the numeric ID to get
6865
```csharp
6966
@{
7067
// Get the page using it's id
71-
var content = contentService.GetById(1234);
68+
var content = ContentService.GetById(1234);
7269
}
7370
```
7471

75-
If Modelsbuilder is enabled you can get the alias of the desired property without using a magic string:
76-
77-
{% include "../../../../.gitbook/includes/obsolete-warning-ipublishedsnapshotaccessor.md" %}
72+
If Models Builder is enabled you can get the alias of the desired property without using a magic string:
7873

7974
```csharp
80-
@inject IPublishedSnapshotAccessor _publishedSnapshotAccessor;
81-
@using Umbraco.Cms.Core.PublishedCache;
75+
@using Umbraco.Cms.Core.PublishedCache
76+
@inject IPublishedContentTypeCache PublishedContentTypeCache
8277
@{
8378
// Set the value of the property with alias 'myDecimal'
84-
content.SetValue(Home.GetModelPropertyType(_publishedSnapshotAccessor, x => x.MyDecimal).Alias, 3);
79+
content.SetValue(Home.GetModelPropertyType(PublishedContentTypeCache, x => x.MyDecimal).Alias, 3);
8580
}
8681
```

0 commit comments

Comments
 (0)