ApplicationManager.CreateObject 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 애플리케이션 도메인 및 개체 형식에 대한 개체를 만듭니다.
오버로드
| Name | Description |
|---|---|
| CreateObject(IApplicationHost, Type) |
형식에 따라 지정된 애플리케이션 도메인에 대한 개체를 만듭니다. |
| CreateObject(String, Type, String, String, Boolean) |
형식, 가상 및 물리적 경로 및 지정된 형식의 개체가 이미 있을 때의 실패 동작을 나타내는 부울 값을 기반으로 지정된 애플리케이션 도메인에 대한 개체를 만듭니다. |
| CreateObject(String, Type, String, String, Boolean, Boolean) |
형식, 가상 및 물리적 경로, 지정된 형식의 개체가 이미 있을 때의 실패 동작을 나타내는 부울 값 및 호스팅 초기화 오류 예외가 throw되는지 여부를 나타내는 부울 값을 기반으로 지정된 애플리케이션 도메인에 대한 개체를 만듭니다. |
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 지정된 형식의 개체가 현재 등록된 경우 예외를 throw하려면 입니다. false 지정된 형식의 기존 등록된 개체를 반환하려면 입니다.
반품
지정된 type개체의 새 개체입니다.
예외
physicalPath가 null인 경우
-또는-
physicalPath 가 유효한 애플리케이션 경로가 아닌 경우
-또는-
type 는 인터페이스를 IRegisteredObject 구현하지 않습니다.
failIfExists 가 true 지정한 형식의 개체가 이미 등록되어 있습니다.
예제
다음 코드 예제는 등록된 개체에 대한 개체 팩터리 디자인 패턴의 구현입니다. 팩터리 패턴을 사용하면 개체의 여러 인스턴스를 등록할 수 있습니다. 이 예제에는 애플리케이션에서 여러 인스턴스를 사용할 개체와 SampleComponent인스턴스 목록을 SampleComponentFactory 관리하는 두 개의 개체SampleComponent가 포함되어 있습니다.
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 메서드는 애플리케이션에서 개체를 만들고 등록하는 데 사용됩니다. 각 형식의 개체를 하나만 만들 수 있습니다. 동일한 형식의 여러 개체를 만들어야 하는 경우 개체 팩터리를 구현해야 합니다. 자세한 내용은 이 항목의 코드 예제를 참조하세요.
고유한 애플리케이션 식별자에 의해 식별되는 각 애플리케이션은 자체 애플리케이션 도메인에서 실행됩니다. 메서드는 CreateObject 매개 변수에 지정된 애플리케이션의 애플리케이션 도메인에 지정된 형식의 개체를 appID 만듭니다. 지정된 애플리케이션에 대한 애플리케이션 도메인이 없으면 개체를 만들기 전에 애플리케이션 도메인이 만들어집니다.
매개 변수는 failIfExists 지정된 형식의 개체가 애플리케이션에 CreateObject 이미 있는 경우 메서드의 동작을 제어합니다. 이 경우 failIfExiststrue메서드는 CreateObject 예외를 InvalidOperationException throw합니다.
이 경우 failIfExists 메서드는 falseCreateObject지정된 형식의 등록된 기존 개체를 반환합니다.
이 메서드는 CreateObject .로 설정된 추가 throwOnError 매개 변수 throwOnError 를 사용하는 오버로드를 호출합니다 false.
적용 대상
CreateObject(String, Type, String, String, Boolean, Boolean)
형식, 가상 및 물리적 경로, 지정된 형식의 개체가 이미 있을 때의 실패 동작을 나타내는 부울 값 및 호스팅 초기화 오류 예외가 throw되는지 여부를 나타내는 부울 값을 기반으로 지정된 애플리케이션 도메인에 대한 개체를 만듭니다.
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 지정된 형식의 개체가 현재 등록된 경우 예외를 throw하려면 입니다. false 지정된 형식의 기존 등록된 개체를 반환하려면 입니다.
- throwOnError
- Boolean
true 호스팅 초기화 오류에 대한 예외를 throw하려면 false 호스팅 초기화 예외를 throw하지 않습니다.
반품
지정된 type개체의 새 개체입니다.
예외
physicalPath가 null인 경우
-또는-
physicalPath 가 유효한 애플리케이션 경로가 아닌 경우
-또는-
type 는 인터페이스를 IRegisteredObject 구현하지 않습니다.
failIfExists 가 true 지정한 형식의 개체가 이미 등록되어 있습니다.
설명
메서드의 CreateObject 이 오버로드는 호스팅 초기화 예외가 throw되는지 여부를 제어할 수 있는 매개 변수를 제공합니다 throwOnError . 제공하지 CreateObject 않는 메서드의 throwOnError 오버로드는 매개 변수가 설정된 상태에서 이 오버로드를 호출합니다false.