ApplicationManager.CreateObject メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定したアプリケーション ドメインとオブジェクトの種類のオブジェクトを作成します。
オーバーロード
| 名前 | 説明 |
|---|---|
| CreateObject(IApplicationHost, Type) |
型に基づいて、指定したアプリケーション ドメインのオブジェクトを作成します。 |
| CreateObject(String, Type, String, String, Boolean) |
型、仮想パス、物理パス、および指定した型のオブジェクトが既に存在する場合のエラー動作を示すブール値に基づいて、指定したアプリケーション ドメインのオブジェクトを作成します。 |
| CreateObject(String, Type, String, String, Boolean, Boolean) |
型、仮想パス、物理パス、指定した型のオブジェクトが既に存在する場合のエラー動作を示すブール値、ホスト初期化エラー例外がスローされるかどうかを示すブール値に基づいて、指定したアプリケーション ドメインのオブジェクトを作成します。 |
CreateObject(IApplicationHost, Type)
型に基づいて、指定したアプリケーション ドメインのオブジェクトを作成します。
public:
System::Web::Hosting::IRegisteredObject ^ CreateObject(System::Web::Hosting::IApplicationHost ^ appHost, Type ^ type);
public System.Web.Hosting.IRegisteredObject CreateObject(System.Web.Hosting.IApplicationHost appHost, Type type);
member this.CreateObject : System.Web.Hosting.IApplicationHost * Type -> System.Web.Hosting.IRegisteredObject
Public Function CreateObject (appHost As IApplicationHost, type As Type) As IRegisteredObject
パラメーター
- appHost
- IApplicationHost
IApplicationHost オブジェクト。
- type
- Type
作成するオブジェクトの型。
返品
typeで指定された型の新しいオブジェクト。
例外
アプリケーションの物理パスが存在しません。
注釈
CreateObject は、.NET Framework バージョン 3.5 で導入されています。 詳細については、「 バージョンと依存関係」を参照してください。
適用対象
CreateObject(String, Type, String, String, Boolean)
型、仮想パス、物理パス、および指定した型のオブジェクトが既に存在する場合のエラー動作を示すブール値に基づいて、指定したアプリケーション ドメインのオブジェクトを作成します。
public:
System::Web::Hosting::IRegisteredObject ^ CreateObject(System::String ^ appId, Type ^ type, System::String ^ virtualPath, System::String ^ physicalPath, bool failIfExists);
public System.Web.Hosting.IRegisteredObject CreateObject(string appId, Type type, string virtualPath, string physicalPath, bool failIfExists);
member this.CreateObject : string * Type * string * string * bool -> System.Web.Hosting.IRegisteredObject
Public Function CreateObject (appId As String, type As Type, virtualPath As String, physicalPath As String, failIfExists As Boolean) As IRegisteredObject
パラメーター
- appId
- String
オブジェクトを所有するアプリケーションの一意識別子。
- type
- Type
作成するオブジェクトの型。
- virtualPath
- String
アプリケーションへの仮想パス。
- physicalPath
- String
アプリケーションへの物理パス。
- failIfExists
- Boolean
true 指定した型のオブジェクトが現在登録されている場合に例外をスローする場合。指定した型の既存の登録済みオブジェクトを返す false します。
返品
指定した typeの新しいオブジェクト。
例外
physicalPath は null です
-又は-
physicalPath は有効なアプリケーション パスではありません。
-又は-
type では、 IRegisteredObject インターフェイスは実装されません。
failIfExists が true され、指定した型のオブジェクトが既に登録されています。
例
次のコード例は、登録済みオブジェクトのオブジェクト ファクトリ デザイン パターンの実装です。 ファクトリ パターンを使用すると、オブジェクトの複数のインスタンスを登録できます。 この例には、アプリケーションが複数のインスタンスを使用するオブジェクトである SampleComponent と、SampleComponentFactory インスタンスの一覧を管理する SampleComponent の 2 つのオブジェクトが含まれています。
using System.Web.Hosting;
public class SampleComponentFactory : IRegisteredObject
{
private ArrayList components = new ArrayList();
public void Start()
{
HostingEnvironment.RegisterObject(this);
}
void IRegisteredObject.Stop(bool immediate)
{
foreach (SampleComponent c in components)
{
((IRegisteredObject)c).Stop(immediate);
}
HostingEnvironment.UnregisterObject(this);
}
public SampleComponent CreateComponent()
{
SampleComponent newComponent = new SampleComponent();
newComponent.Initialize();
components.Add(newComponent);
return newComponent;
}
}
public class SampleComponent : IRegisteredObject
{
void IRegisteredObject.Stop(bool immediate)
{
// Clean up component resources here.
}
public void Initialize()
{
// Initialize component here.
}
}
Imports System.Web.Hosting
Public Class SampleComponentFactory
Implements IRegisteredObject
Dim components As ArrayList = New ArrayList()
Public Sub Start()
HostingEnvironment.RegisterObject(Me)
End Sub
Public Sub [Stop](ByVal immediate As Boolean) Implements System.Web.Hosting.IRegisteredObject.Stop
For Each c As SampleComponent In components
CType(c, IRegisteredObject).Stop(immediate)
Next
HostingEnvironment.UnregisterObject(Me)
End Sub
Public Function CreateComponent() As SampleComponent
Dim newComponent As SampleComponent
newComponent = New SampleComponent
newComponent.Initialize()
components.Add(newComponent)
Return newComponent
End Function
End Class
Public Class SampleComponent
Implements IRegisteredObject
Sub [Stop](ByVal immediate As Boolean) Implements System.Web.Hosting.IRegisteredObject.Stop
' Clean up component resources here.
End Sub
Public Sub Initialize()
' Initialize component here.
End Sub
End Class
注釈
CreateObject メソッドは、アプリケーションでオブジェクトを作成および登録するために使用されます。 各型のオブジェクトは 1 つだけ作成できます。 同じ型の複数のオブジェクトを作成する必要がある場合は、オブジェクト ファクトリを実装する必要があります。 詳細については、このトピックのコード例を参照してください。
一意のアプリケーション識別子で識別される各アプリケーションは、独自のアプリケーション ドメインで実行されます。
CreateObject メソッドは、appID パラメーターで指定されたアプリケーションのアプリケーション ドメインに、指定した型のオブジェクトを作成します。 指定したアプリケーションのアプリケーション ドメインが存在しない場合は、オブジェクトが作成される前にドメインが作成されます。
failIfExists パラメーターは、指定した型のオブジェクトが既にアプリケーションに存在する場合のCreateObject メソッドの動作を制御します。
failIfExistsがtrueされると、CreateObject メソッドはInvalidOperationException例外をスローします。
failIfExistsがfalseされると、CreateObject メソッドは、指定した型の既存の登録済みオブジェクトを返します。
CreateObject メソッドは、throwOnErrorが throwOnError に設定された追加のfalse パラメーターを受け取るオーバーロードを呼び出します。
適用対象
CreateObject(String, Type, String, String, Boolean, Boolean)
型、仮想パス、物理パス、指定した型のオブジェクトが既に存在する場合のエラー動作を示すブール値、ホスト初期化エラー例外がスローされるかどうかを示すブール値に基づいて、指定したアプリケーション ドメインのオブジェクトを作成します。
public:
System::Web::Hosting::IRegisteredObject ^ CreateObject(System::String ^ appId, Type ^ type, System::String ^ virtualPath, System::String ^ physicalPath, bool failIfExists, bool throwOnError);
public System.Web.Hosting.IRegisteredObject CreateObject(string appId, Type type, string virtualPath, string physicalPath, bool failIfExists, bool throwOnError);
member this.CreateObject : string * Type * string * string * bool * bool -> System.Web.Hosting.IRegisteredObject
Public Function CreateObject (appId As String, type As Type, virtualPath As String, physicalPath As String, failIfExists As Boolean, throwOnError As Boolean) As IRegisteredObject
パラメーター
- appId
- String
オブジェクトを所有するアプリケーションの一意識別子。
- type
- Type
作成するオブジェクトの型。
- virtualPath
- String
アプリケーションへの仮想パス。
- physicalPath
- String
アプリケーションへの物理パス。
- failIfExists
- Boolean
true 指定した型のオブジェクトが現在登録されている場合に例外をスローする場合。指定した型の既存の登録済みオブジェクトを返す false します。
- throwOnError
- Boolean
true 初期化エラーをホストするための例外をスローする場合。ホスティング初期化例外をスローしないように false します。
返品
指定した typeの新しいオブジェクト。
例外
physicalPath は null です
-又は-
physicalPath は有効なアプリケーション パスではありません。
-又は-
type では、 IRegisteredObject インターフェイスは実装されません。
failIfExists が true され、指定した型のオブジェクトが既に登録されています。
注釈
CreateObject メソッドのこのオーバーロードは、throwOnError パラメーターを提供します。これにより、ホスティング初期化例外がスローされるかどうかを制御できます。
CreateObjectを提供しないthrowOnError メソッドのオーバーロードは、パラメーターを false に設定してこのオーバーロードを呼び出します。