ApplicationManager.CreateObject 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 애플리케이션 도메인에 대한 개체 및 개체 형식을 만듭니다.
오버로드
| 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
지정된 형식의 개체가 현재 등록된 경우 예외를 throw하려면 true이고, 지정된 형식의 등록된 기존 개체를 반환하려면 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 메서드는 지정 된 형식의 개체는 애플리케이션에 이미 있는 경우. 이 true경우 failIfExists 메서드는 CreateObject 예외를 InvalidOperationException throw합니다.
이 경우 failIfExists 메서드는 CreateObject false지정된 형식의 기존 등록된 개체를 반환합니다.
이 메서드는 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
지정된 형식의 개체가 현재 등록된 경우 예외를 throw하려면 true이고, 지정된 형식의 등록된 기존 개체를 반환하려면 false입니다.
- throwOnError
- Boolean
호스팅 초기화 오류에 대한 예외를 throw하려면 true이고, 그렇지 않으면 false입니다.
반환
지정된 type의 새 개체입니다.
예외
physicalPath가 null인 경우
또는
physicalPath가 잘못된 애플리케이션 경로인 경우
또는
type 가 IRegisteredObject 인터페이스를 구현하지 않습니다.
failIfExists가 true이고 지정된 형식의 개체가 이미 등록된 경우
설명
메서드의 CreateObject 이 오버로드는 초기화 예외 호스팅이 throw되는지 여부를 제어할 수 있는 매개 변수를 제공합니다 throwOnError . 매개 변수false를 사용하여 이 오버로드를 CreateObject 호출하지 않는 throwOnError 메서드의 오버로드입니다.