Skip to content

Commit 5767982

Browse files
Make server aware of CSLA versions, add v10 examples (#4)
* Initial implementation of CSLA version support * Update metadata * Add v10 examples
1 parent 44e1834 commit 5767982

25 files changed

+704
-186
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
**/obj
2222
**/secrets.dev.yaml
2323
**/values.dev.yaml
24+
**/changelogs
2425
LICENSE
2526
README.md
2627
!**/.gitignore

.github/copilot-instructions.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# GitHub Copilot Instructions
2+
3+
Welcome to the `csla-mcp` repository! To ensure Copilot provides relevant and high-quality suggestions, please follow these guidelines:
4+
5+
## Coding Style
6+
- Use consistent indentation (4 spaces).
7+
- Prefer explicit variable names.
8+
- Follow C# conventions for naming and structure.
9+
10+
## Documentation
11+
- Add XML comments to public classes and methods.
12+
- Use summary tags for method descriptions.
13+
14+
## Best Practices
15+
- Write clean, maintainable code.
16+
- Avoid hardcoding values; use configuration where possible.
17+
- Implement error handling and logging.
18+
19+
## Pull Requests
20+
- Ensure code is tested before submitting.
21+
- Include a clear description of changes.
22+
23+
## Copilot Usage
24+
- Use Copilot to generate boilerplate, tests, and documentation.
25+
- Review and edit Copilot suggestions for accuracy and security.
26+
27+
## Change logs and change documents
28+
- Create all change logs and change documents in the `changelogs` folder.
29+
- When documenting fixes or other changes, put the documents in the `changelogs` folder.
30+
31+
Thank you for contributing!

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
##
44
## Get latest from `dotnet new gitignore`
55

6+
changelogs/
7+
68
# dotenv files
79
.env
810

SEMANTIC_SEARCH_README.md

Lines changed: 0 additions & 159 deletions
This file was deleted.

csla-examples/v10/Command.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Command Stereotype
2+
3+
This example demonstrates a complete CSLA business class named `CustomerExists` that includes various property types and data access methods. The class derives from `CommandBase<T>` and includes properties for input parameters and output results.
4+
5+
This class demonstrates the command business class stereotype.
6+
7+
It also includes a data portal operation method for executing the command. Note that the data access method contains a placeholder comment where actual data access logic should be invoked.
8+
9+
```csharp
10+
using System;
11+
using Csla;
12+
13+
[CslaImplementProperties]
14+
public partial class CustomerExists : CommandBase<CustomerExists>
15+
{
16+
public partial bool Exists { get; set; }
17+
18+
[Execute]
19+
private async Task Execute(string email, [Inject] ICustomerDal dal)
20+
{
21+
// Placeholder for actual data access logic
22+
var customer = await dal.GetByEmailAsync(email);
23+
Exists = customer != null;
24+
}
25+
}
26+
```
27+
28+
> **Note:** The `ICustomerDal` interface is assumed to be defined elsewhere in your codebase and is responsible for data access operations related to customers. The `GetByEmailAsync` method is a placeholder for the actual implementation that retrieves a customer by their email address.
29+
30+
This class can be used to check if a customer with a specific email address exists in the data store by setting the `Email` property and then calling the data portal to execute the command. The result will be available in the `Exists` property.
31+
32+
To execute this command, you would typically do something like the following:
33+
34+
```csharp
35+
var command = await customerExistsPortal.ExecuteAsync("[email protected]");
36+
bool customerExists = command.Exists;
37+
```
38+
39+
This assumes `customerExistsPortal` is a service of type `IDataPortal<CustomerExists>`.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# CSLA .NET Class Library
2+
3+
Most CSLA .NET applications use a class library project to hold the business classes. This project typically references the CSLA .NET framework and any other necessary libraries.
4+
5+
```xml
6+
<Project Sdk="Microsoft.NET.Sdk">
7+
8+
<PropertyGroup>
9+
<TargetFramework>net10.0</TargetFramework>
10+
<Nullable>enable</Nullable>
11+
<ImplicitUsings>enable</ImplicitUsings>
12+
<LangVersion>14</LangVersion>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="Csla" Version="10.0.0" />
17+
<PackageReference Include="Csla.Generator.AutoImplementProperties.CSharp" Version="10.0.0"
18+
OutputItemType="Analyzer"
19+
ReferenceOutputAssembly="false"/>
20+
</ItemGroup>
21+
</Project>
22+
```
23+
24+
CSLA 10 supports `TargetFramework` of .NET Framework 4.8, net8.0, net9.0, and net10.0.
25+
26+
CSLA 10 supports nullable reference types in its API, so `Nullable` is enabled.
27+
28+
CSLA 10 uses features from C# version 14, so the `LangVersion` is set to 14 (or higher).
29+
30+
The `Csla` package is referenced to enable the use of CSLA .NET features such as the rules engine, data portal, and other capabilities.
31+
32+
The `AutoImplementProperties` code generator package is referenced to enable standard code generation for CSLA properties.

csla-examples/v10/EditableChild.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Editable Child Stereotype
2+
3+
This example demonstrates a complete CSLA business class named `OrderItemEdit` that includes various property types, business rules, authorization rules, and data access methods. The class derives from `BusinessBase<T>` and includes both read-only and read-write properties.
4+
5+
This class demonstrates the editable child business class stereotype.
6+
7+
It also shows how to implement business rules for validation, including required fields and range constraints. Additionally, it includes object-level authorization rules to control access based on user roles.
8+
9+
It also includes data portal operation methods for creating, fetching, inserting, updating, and deleting order item records. Note that the data access methods contain placeholder comments where actual data access logic should be invoked.
10+
11+
```csharp
12+
using System;
13+
using System.ComponentModel.DataAnnotations;
14+
using Csla;
15+
16+
[CslaImplementProperties]
17+
public partial class OrderItemEdit : BusinessBase<OrderItemEdit>
18+
{
19+
public partial int Id { get; private set; }
20+
[Required]
21+
[StringLength(100)]
22+
public partial string ProductName { get; set; }
23+
[Range(1, 1000)]
24+
public partial int Quantity { get; set; }
25+
[Range(0.01, 10000.00)]
26+
public partial decimal Price { get; set; }
27+
28+
protected override void AddBusinessRules()
29+
{
30+
base.AddBusinessRules();
31+
// Add any custom business rules here if needed
32+
}
33+
34+
protected override void AddAuthorizationRules()
35+
{
36+
base.AddAuthorizationRules();
37+
// Example: Only users in the "Manager" role can edit the Price property
38+
BusinessRules.AddRule(new Csla.Rules.CommonRules.IsInRole(PriceProperty, "Manager"));
39+
}
40+
41+
[CreateChild]
42+
private void CreateChild()
43+
{
44+
// Initialize default values here if needed
45+
LoadProperty(QuantityProperty, 1);
46+
LoadProperty(PriceProperty, 0.01);
47+
}
48+
49+
[FetchChild]
50+
private void FetchChild(OrderDetailData data)
51+
{
52+
// Load properties from data object
53+
LoadProperty(IdProperty, data.Id);
54+
LoadProperty(ProductNameProperty, data.ProductName);
55+
LoadProperty(QuantityProperty, data.Quantity);
56+
LoadProperty(PriceProperty, data.Price);
57+
}
58+
59+
[InsertChild]
60+
private void InsertChild([Inject] IOrderDetailDal dal)
61+
{
62+
var data = new OrderDetailData
63+
{
64+
ProductName = ReadProperty(ProductNameProperty),
65+
Quantity = ReadProperty(QuantityProperty),
66+
Price = ReadProperty(PriceProperty)
67+
};
68+
var newId = dal.Insert(data);
69+
LoadProperty(IdProperty, newId);
70+
}
71+
72+
[UpdateChild]
73+
private void UpdateChild([Inject] IOrderDetailDal dal)
74+
{
75+
var data = new OrderDetailData
76+
{
77+
Id = ReadProperty(IdProperty),
78+
ProductName = ReadProperty(ProductNameProperty),
79+
Quantity = ReadProperty(QuantityProperty),
80+
Price = ReadProperty(PriceProperty)
81+
};
82+
dal.Update(data);
83+
}
84+
85+
[DeleteSelfChild]
86+
private void DeleteSelfChild([Inject] IOrderDetailDal dal)
87+
{
88+
dal.Delete(ReadProperty(IdProperty));
89+
}
90+
}
91+
```

0 commit comments

Comments
 (0)