開発記その 4 - Domain Service の引数にエンティティ -

やっとユーザー作成の完成です。サボりすぎ。。

で、表題の件ではまりました。

ユーザー作成は Silverlight の BusinessApplication のテンプレートについてるのですが、そのまま使うのではなく、抜き出す形で MembershipService っていう名前で作りました。

メソッドは CreateUser っていうのをひとつだけ作って、引数は CreateUserData ってのをそのまま使ってます。

[Invoke(HasSideEffects = true)]
public CreateUserStatus CreateUser(CreateUserData user, string password) 

で、コンパイルするとコンパイルエラー。

エラー	1	Operation named 'CreateUser' does not conform to the required signature. Parameter types must be an entity type or one of the predefined serializable types.	MoneyBook

とりあえず、MSDN に直行してみたのですが Invoke オペレーションの引数は何でも OK って書いてあります。

http://msdn.microsoft.com/en-us/library/ee707373%28v=VS.91%29.aspx

仕方ないので、ネットで 1 時間くらいうろついたのですがめぼしい情報がなくって BusinessApplicatoin のテンプレートに戻ったら発見しました。

どうやら、現状では戻り値で戻ってる型じゃないとダメっぽいです。

/// <summary>
/// Query method that exposes the <see cref="RegistrationData"/> class to Silverlight client code.
/// </summary>
/// <remarks>
/// This query method is not used and will throw <see cref="NotSupportedException"/> if called.
/// Its primary job is to indicate the <see cref="RegistrationData"/> class should be made
/// available to the Silverlight client.
/// </remarks>
/// <returns>Not applicable.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
public IEnumerable<RegistrationData> GetUsers()

で、以下のようなメソッドを追加したら無事にコンパイルが通りました。

[Query(IsComposable = false)]
public CreateUserData GetCreateUserData() {
    throw new NotSupportedException();
}


さて、これでやっとユーザー作成は完了しました。


※今回のチェックイン
http://moneybook.codeplex.com/SourceControl/changeset/changes/53069